C# 提取汉字

来源:互联网 发布:掉头发 洗发水 知乎 编辑:程序博客网 时间:2024/06/04 00:57

[csharp] view plaincopy
  1. <span style="white-space:pre">  </span>protected string getChinese(string str)  
  2.         {  
  3.             string mystr = "", ResultString="";  
  4.             for (int i = 0; i < str.Length - 1; i++)  
  5.             {  
  6.                 mystr = str.Substring(i, 1);  
  7.                 if (str != "")  
  8.                 {  
  9.                     if (Regex.IsMatch(mystr, "[\u4e00-\u9fa5]"))  
  10.                         ResultString += mystr;  
  11.                 }  
  12.             }  
  13.             return ResultString;  
  14.         }  
0 0
原创粉丝点击