天天看點

判斷字元串中是否包含中文

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()

    {

    }

}

繼續閱讀