正則表達式之提取中文


         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