正则表达式之提取中文


         static void Main(string[] args)
         {
            string str = "asd=-.我是中文{asdasd";
            Console.WriteLine(GetChineseWord(str));
            Console.ReadKey();

         }
          public static string GetChineseWord(string oriText)
          {
            string x = @"[\u4E00-\u9FFF]+";
            MatchCollection Matches = Regex.Matches
            (oriText, x, RegexOptions.IgnoreCase);
            StringBuilder sb = new StringBuilder();
            foreach (Match NextMatch in Matches)
            {
                sb.Append(NextMatch.Value);
            }
            return sb.ToString();
          }    

很简单,不想废话,最终控制台输出的就是“我是中文”这几个字


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM