如题所述
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));
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));
温馨提示:答案为网友推荐,仅供参考