亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#實(shí)現(xiàn)判斷字符串中是否包含中文的方法

 更新時(shí)間:2014年08月04日 15:23:35   投稿:shichen2014  
這篇文章主要介紹了C#實(shí)現(xiàn)判斷字符串中是否包含中文的方法,非常實(shí)用的功能,需要的朋友可以參考下

本實(shí)例展示了C#實(shí)現(xiàn)判斷字符串中是否包含中文的方法,是一個(gè)非常實(shí)用的功能,對(duì)初學(xué)者來(lái)說(shuō)有一定的借鑒學(xué)習(xí)價(jià)值,具體實(shí)現(xiàn)方法如下:

主要功能代碼如下:

/// <summary>
/// 判斷字符串中是否包含中文
/// </summary>
/// <param name="str">需要判斷的字符串</param>
/// <returns>判斷結(jié)果</returns>
public static bool HasChinese(this string str)
{
  return Regex.IsMatch(str, @"[\u4e00-\u9fa5]");
}

單元測(cè)試代碼如下:

[TestMethod()]
public void HasChineseTest()
{
  string _chineseStr1 = "你好Word";
  bool _expected1 = true;
  bool _actual1 = StringToolV2.HasChinese(_chineseStr1);
  Assert.AreEqual(_expected1, _actual1);

  string _chineseStr2 = "Hello World";
  bool _expected2 = false;
  bool _actual2 = StringToolV2.HasChinese(_chineseStr2);
  Assert.AreEqual(_expected2, _actual2);
}

測(cè)試結(jié)果如下:

相關(guān)文章

最新評(píng)論