``
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 字符Char
{
class Program
{
static void Main( string[] args )
{
char[] szInput = Console.ReadLine().ToString().ToCharArray(); // 字符串转换为字符数组的方法:字符串名.ToCharArray(),前边要用字符数字接
for( int i = 0; i < szInput.Length; i++ ) {
if( Char.IsLetter( szInput[ i ] ) == true ) {
Console.WriteLine( "所输入的字符串中第{0}位是字母",i+1 );
} // 因为IsLetter是一个静态方法,所以不能写成“szInput.IsLetter”,必须要用类名调用
if( Char.IsDigit( szInput[i] ) == true ) {
Console.WriteLine( "所输入的字符串中第{0}位是数字", 1 + i );
}
if( Char.IsPunctuation( szInput[ i ] ) == true ) {
Console.WriteLine( "所输入的字符串中第{0}位是标点符号", 1 + i );
}
if( Char.IsWhiteSpace( szInput[ i ] ) == true ) {
Console.WriteLine( "所输入的字符串中第{0}位是空格", 1 + i );
}
}
Console.ReadKey();
}
}
}
![运行结果](https://img-blog.csdnimg.cn/20191011223104850.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0p1bV9w,size_16,color_FFFFFF,t_70)
Char字符
最新推荐文章于 2024-05-15 12:19:54 发布