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])一个一个字符判断。
标签:字符串,数字,字母
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C#枚举类型与位域枚举Enum
2023-03-02 06:52:27
android AudioRecorder简单心得分享
2021-12-13 08:23:46
Java Web项目部署在Tomcat运行出错与解决方法示例
2023-07-18 02:50:47
![](https://img.aspxhome.com/file/2023/2/57622_0s.png)
Android 自定义imageview实现图片缩放实例详解
2023-03-08 10:56:08
![](https://img.aspxhome.com/file/2023/0/125530_0s.png)
Java基于Socket实现多人聊天室
2022-11-08 14:11:12
在Flutter中制作翻转卡片动画的完整实例代码
2023-06-23 23:31:21
Java使用entrySet方法获取Map集合中的元素
2022-08-06 17:41:05
详解C#借助.NET框架中的XmlTextReader类读取XML的方法
2023-01-18 23:31:47
![](https://img.aspxhome.com/file/2023/8/75578_0s.jpg)
WebService教程详解(一)
2022-02-26 09:59:50
Java 常见的限流算法详细分析并实现
2022-01-05 22:11:09
![](https://img.aspxhome.com/file/2023/3/71923_0s.png)
如何利用泛型封装通用的service层
2023-05-15 04:55:43
SpringBoot深入浅出分析初始化器
2022-07-06 09:05:59
解决Eclipse创建android项目无法正常预览布局文件问题的方法
2023-07-31 09:51:12
![](https://img.aspxhome.com/file/2023/6/82316_0s.png)
Android Apk反编译及加密教程
2022-01-13 01:01:25
![](https://img.aspxhome.com/file/2023/8/125378_0s.png)
Android中Service实时向Activity传递数据实例分析
2022-07-22 20:44:15
![](https://img.aspxhome.com/file/2023/3/95013_0s.png)
Java线程之守护线程(Daemon)用法实例
2023-11-29 09:15:13
C语言之如何求三次方根
2022-04-30 03:13:52
![](https://img.aspxhome.com/file/2023/2/131942_0s.png)
java实现文件上传下载功能
2021-11-26 17:19:05
![](https://img.aspxhome.com/file/2023/7/85887_0s.jpg)
android判断一个Activity是否处于栈顶的实例
2021-06-24 18:37:39
Android自定义view仿淘宝快递物流信息时间轴
2022-02-20 18:51:16
![](https://img.aspxhome.com/file/2023/7/139387_0s.jpg)