文章内容

2017/5/9 15:31:04,作 者: 黄兵

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("你输入的不是数字~!");
}
分享到:

发表评论

评论列表