使用正则表达式可以快速的判断字符串中是否有中文。
代码示例:
- string test1 = "asdasdas121312/*-";
- string test2 = "阿三大苏打";
- string test3 = "asda阿三大苏打__132";
-
- private void Start()
- {
- Debug.Log(HasChinese(test1));
- Debug.Log(HasChinese(test2));
- Debug.Log(HasChinese(test3));
- }
-
- /// <summary>
- /// 判断字符串中是否包含中文
- /// </summary>
- /// <param name="str">需要判断的字符串</param>
- /// <returns>判断结果</returns>
- public bool HasChinese(string str)
- {
- return Regex.IsMatch(str, @"[\u4e00-\u9fa5]");
- }
输出:

核心代码:
- public bool HasChinese(string str)
- {
- return Regex.IsMatch(str, @"[\u4e00-\u9fa5]");
- }





![战神引擎传奇手游【1.76盛战传奇免授权版[摸摸登陆器]】最新整理Win系复古服务端+安卓苹果双端+GM授权物品后台+详细搭建教程](https://cdn.jxasp.com:9143/image/20251106/1B4E8594B3BEB90E8601D63A8A39CB0B.jpg)













