日期:2014-05-17  浏览次数:21037 次

c#如何求一个字符串中汉字的数量
c#如何求一个字符串中汉字的数量

------解决方案--------------------
汉字好像是这个 ^[\u4E00-\u9FFF]+$
------解决方案--------------------

int count=(from s in str where s > 0x4E00 && s < 0x9FA5 select s).Count();

------解决方案--------------------

var u = from s in str
        where s > 0x4E00 && s < 0x9FA5
        select s;
        //
        u.ToList().ForEach
        (s =>
            {
               Console.Write(s + " ");
            }
        );
        //
Console.WriteLine(u.Count());

------解决方案--------------------
MatchCollection mc = Regex.Match(str, @"[\u4E00-\u9FFF]");
int count = mc.Count;
------解决方案--------------------

List<char> cCharacters = new List<char>();
for (int i = 0; i < str.Length; i++)
{
   if (str[i] > 0x4E00 && str[i] < 0x9FA5)
        cCharacters.Add(str[i]);
}
foreach (char ch in cCharacters)
{
    Console.Write(ch+" ");
}
Console.WriteLine(cCharacters.Count);