软件编程
位置:首页>> 软件编程>> C#编程>> c#中判断字符串是不是数字或字母的方法

c#中判断字符串是不是数字或字母的方法

  发布时间:2023-02-10 06:08:49 

标签:字符串,数字,字母

一、判断字母


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])一个一个字符判断。

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com