日期:2014-05-18 浏览次数:20961 次
string s = @"你好!I am a 菜鸟!"; Console.WriteLine("英文字母有" + Regex.Matches(s, @"[A-Za-z]").Count + "个"); Console.WriteLine("汉字有" + Regex.Matches(s, @"[\u4e00-\u9fa5]").Count + "个"); Console.WriteLine("空格有" + Regex.Matches(s, @" ").Count + "个"); Console.WriteLine("其他字符有" + Regex.Matches(s, @"[^A-Za-z\u4e00-\u9fa5 ]").Count + "个"); Console.ReadKey();