关键词搜索

源码搜索 ×
×

c# 判断字符串中有中文字符

发布2021-01-06浏览922次

详情内容

使用正则表达式可以快速的判断字符串中是否有中文。

代码示例:

  1. string test1 = "asdasdas121312/*-";
  2. string test2 = "阿三大苏打";
  3. string test3 = "asda阿三大苏打__132";
  4. private void Start()
  5. {
  6. Debug.Log(HasChinese(test1));
  7. Debug.Log(HasChinese(test2));
  8. Debug.Log(HasChinese(test3));
  9. }
  10. /// <summary>
  11. /// 判断字符串中是否包含中文
  12. /// </summary>
  13. /// <param name="str">需要判断的字符串</param>
  14. /// <returns>判断结果</returns>
  15. public bool HasChinese(string str)
  16. {
  17. return Regex.IsMatch(str, @"[\u4e00-\u9fa5]");
  18. }

输出:

核心代码:

  1. public bool HasChinese(string str)
  2. {
  3. return Regex.IsMatch(str, @"[\u4e00-\u9fa5]");
  4. }

 

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载