using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.UI;
public class NewBehaviourScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
GameObject.Find("com_btn").GetComponent<Button>().onClick.AddListener(() => {
string str = GameObject.Find("com_inp").GetComponent<InputField>().text;
if (str.Length <= 0)
{
str = "输入为空";
}
GameObject.Find("com_txt").GetComponent<Text>().text = str;
});
GameObject.Find("com_btn2").GetComponent<Button>().onClick.AddListener(() => {
string str = GameObject.Find("com_inp").GetComponent<InputField>().text;
str = FilterEmoji(str);
if (str.Length <= 0)
{
str = "输入为空";
}
GameObject.Find("com_txt2").GetComponent<Text>().text = str;
});
}
List<string> patten = new List<string>() { @"\p{Cs}", @"\p{Co}", @"\p{Cn}", @"[\u2702-\u27B0]" };
private string FilterEmoji(string str)
{
for (int i = 0; i < patten.Count; i++)
{
str = Regex.Replace(str, patten[i], "");//屏蔽emoji
}
return str;
}
}
unity场景
