用ascii代码检查条件? [英] Check condition with ascii code?

查看:128
本文介绍了用ascii代码检查条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

如果使用ascii代码检查条件,请使用以下代码?

I the below code if condition checked with ascii code?

谢谢

private void keypress_event(object sender, KeyPressEventArgs e) { Button b = new Button(); b.Text = e.KeyChar.ToString(); if (e.KeyChar >= '0' && e.KeyChar <= '9') // check with ascii code?

条件检查keychar应该在1到9之间(数字)
{
btnAllnum_click(b,null);
}
} Word 2007

The condition check keychar shoud be between 1 to 9(number) { btnAllnum_click(b, null); } }Word 2007

推荐答案

要比较charC类型的KeyChar和不是char的其他东西(例如整数ascii代码),首先必须将两条信息中的一条转换为另一条的类型,即将KeyChar转换为int
然后与ascii代码进行比较,或者将ascii代码转换为char,然后将其与KeyChar:

To compare the KeyChar, which is of type char, with something else which is not a char (such as an integer ascii code), you first have to convert one of the two pieces of information to the type of the other, i.e., either convert the KeyChar to int and then compare to the ascii code, or convert the ascii code to char and then compare to the KeyChar:

如果 <(>)( e KeyChar))
> =   48 && ((int)(e KeyChar))
< = 57 )...

if (((int)(e.KeyChar)) >= 48 && ((int)(e.KeyChar)) <= 57) ...

- 或 -

如果 e KeyChar
> =   (char)48 && e KeyChar
< = (char)57 )...

if (e.KeyChar >= (char)48 && e.KeyChar <= (char)57) ...


这篇关于用ascii代码检查条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆