标签:
Console.WriteLine("请输入一段文字;"); string str = Console.ReadLine(); int sum =str.Length;//定义一个值变量用来记录汉字的个数。 for (int i = 0; i < str.Length; i++) { string s = str.Substring(i, 1); try { int a = int.Parse(s); sum--; } catch { } } Console.WriteLine(sum); Console.ReadLine();
注:若是这段文字中含有汉字,数字和字母三类,则得用正则表达式来判断汉字的个数。
输入一段文字(里面仅有汉字和数字组成),输出这段文字中汉字的个数。
标签:
原文地址:http://www.cnblogs.com/kangshuai/p/4563643.html