public string CharStat(string str)
{
int digitCount = 0;
int leterCount = 0;
int spaceCount = 0;
int chineseLeterCount = 0;
int ortherLeterCount = 0;
for (int i=0; i < str.Length; i++)
{
if (Char.IsDigit(str, i))
{
digitCount++; //统计数字
}
else if(Char.IsWhiteSpace(str,i))
{
spaceCount++;//统计空格
}
else if(Char.ConvertToUtf32(str,i) >= Convert.ToInt32("4e00", 16) && Char.ConvertToUtf32(str,i) <= Convert.ToInt32("9fff", 16) )
{
chineseLeterCount ++;//统计汉字
}
else if (Char.IsLetter(str, i))
{
leterCount++;//统计字母,包括汉字
}
else
{
ortherLeterCount++;//其他字符
}
}
return string.Format(str + "中,数字{0}个,字母{1}个,空格{2}个,汉字{3}个,其他字符{4}个", digitCount, leterCount, spaceCount, chineseLeterCount, ortherLeterCount);