c#中判断是不是数字和字母

一、判断字母
string str = Console.ReadLine();
if (char.isLetter(str))
{

}
else if (char.IsDigit(str))
{

}
if(ch>='a'&&ch<='z') 小写字母
if(ch>='A'&&ch<='Z') 大写字母
数字也一样。

判断汉字一般是输入 >255 因为汉字是大字符集

二、判断输入的是不是数字
try
{
int n = 0;
n = int.Parse(this.textBox1.Text.Trim());
}
catch
{
MessageBox.Show("你输入的不是数字~!");
}

也可以用Char.isNumber(str[i])一个一个字符判断。

posted on 2011-04-16 18:26  Osiris4Net  阅读(3093)  评论(0编辑  收藏  举报

导航