C#中获去一个字符串中的汉字的个数 C#获取字符串全角的个数

it2022-05-05  93

     

static void Main(string[] args)        {            while (true)            {

      Console.WriteLine("输入一串字符");                string str = Console.ReadLine();//定义一个变量str用来存储输入的字符串                int num= Encoding.Default.GetByteCount(str);//Encoding.Default.GetByteCount(str)在系统默认下计算对字符进行编码是所产生的字节数                int len = str.Length;//获取字符串的长度                Console.WriteLine("有{0}汉字",num-len);//num-len就是字符串中的汉字个数                      }        }

转载于:https://www.cnblogs.com/zzuhjf/archive/2011/07/19/2110360.html

相关资源:DirectX修复工具V4.0增强版

最新回复(0)