zoukankan      html  css  js  c++  java
  • unity插件,从一段文字中提取中文并去重

    using System.Collections.Generic;
    using System.Text.RegularExpressions;
    using UnityEditor;
    using UnityEngine;
    
    public class ChineseCharPicker : EditorWindow
    {
        string inString = "在这里输入";
        string outString = "";
    
        void OnGUI()
        {
            GUILayout.Label("原始内容", EditorStyles.boldLabel);
            inString = EditorGUILayout.TextArea(inString);
    
            GUILayout.Label("结果", EditorStyles.boldLabel);
            outString = EditorGUILayout.TextArea(outString);
    
            bool button = GUILayout.Button("提取", EditorStyles.miniButton);
            if (button)
            {
                Debug.Log("执行成功" + Time.time);
                convert();
            }
        }
    
        [MenuItem("Window/中文提取器")]
        public static void ShowWindow()
        {
            GetWindow(typeof(ChineseCharPicker));
        }
    
    
        public string pick(string str)
        {
            string rex = "[^\一-\龥]+";
            return Regex.Replace(str, rex, "");
        }
    
        public void convert()
        {
            outString = delete(pick(inString));
        }
    
        private string delete(string str)
        {
            char[] chars = str.ToCharArray();
            HashSet<string> result = new HashSet<string>();
            foreach (char c in chars)
            {
                result.Add("" + c);
            }
    
            string sb = "";
            foreach (string str1 in result)
            {
                sb += str1;
            }
            return sb;
        }
    }

    把上面代码保存为ChineseCharPicker.cs放到Assets/Editor即可

  • 相关阅读:
    项目进展1
    团队项目(百药食坊)介绍
    结对编程—黄金点游戏(庞思瑶&季远琦)
    WC项目
    四则运算
    Week3——Session
    Spring IOC (DI-依赖注入)
    Week2——XML
    Week2——提交表单后后台的工作
    Week1——JavaEE
  • 原文地址:https://www.cnblogs.com/xirtam/p/6673350.html
Copyright © 2011-2022 走看看