天天看点

判断字符串中是否包含中文

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using System.Text.RegularExpressions;//先导入这个使用正则表达式

public class ContainsChinese : MonoBehaviour

{

    Regex reg = new Regex(@"[\u4e00-\u9fa5]");//正则表达式

    string str = "smile";

    // Use this for initialization

    void Start()

    {

        if (reg.IsMatch(str))

        {

           Debug .Log("有汉字");

        }

        else

        {

            Debug.Log("没汉字");

        }

    }

    // Update is called once per frame

    void Update()

    {

    }

}

继续阅读