最普遍的方法,逐個循環
一開始用的是這種方法,后來覺得要寫太多行了,不想寫,就去找到了其他方法
1 //判斷原字符串是否包含漢字 2 for (int i = 0; i < poDate.Length; i++) 3 { 4 //正則表達式逐個字符判斷是否為漢字 5 if (Regex.IsMatch(poDate[i].ToString(), @"[\u4e00-\u9fbb]+")) 6 { 7 //是漢字 8 _poDate.Remove(i, 1); 9 _poDate.Insert(i, '/'); 10 } 11 }
然后發現兩個其實是一樣的,也不知道當時為什么要這么寫,
可能是為了替換吧,別的原因是想不到了
1 if (Regex.IsMatch(str, @"[\u4e00-\u9fa5]")) 2 { 3 Console.WriteLine("yes"); 4 } 5 else 6 { 7 Console.WriteLine("no"); 8 }
最后上引用,正則表達式的引用
1 using System.Text.RegularExpressions;