用C#语言写,从键盘输入一系列字符,以回车符。分别统计字母,数字,空格,其他字符的个数并输出。
1个回答
展开全部
using System.Text.RegularExpressions;
string readString = Console.ReadLine();
MatchCollection numMatches = Regex.Matches(readString, @"[\d]");
MatchCollection spaceMatches = Regex.Matches(readString, @" ");
MatchCollection charMatches = Regex.Matches(readString, @"(?![\d])(?![ ])([\s\S])");
Console.WriteLine(string.Format("数字{0}个,字母{1}个,空格{2}", numMatches.Count, charMatches.Count, spaceMatches.Count));
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询