unity C# 含有实体字符的字符串转换成正常的字符串

来源:互联网 发布:caj什么软件打开 编辑:程序博客网 时间:2024/06/08 19:40
using UnityEngine;using System.Collections;using System.Text;using System.Text.RegularExpressions;public class TTTTTTst : MonoBehaviour{// Use this for initializationvoid Start (){// ' 等于 'Debug.LogWarning (ReplaceCodes("what's your name"));}public static string ReplaceCodes (string target){Regex codeSequence = new Regex (@"&#[0-9]{1,3};");MatchCollection matches = codeSequence.Matches (target);StringBuilder resultStringBuilder = new StringBuilder (target);foreach (Match match in matches) {string matchedCodeExpression = match.Value;string matchedCode = matchedCodeExpression.Substring (2, matchedCodeExpression.Length - 3);byte resultCode = byte.Parse (matchedCode);resultStringBuilder.Replace (matchedCodeExpression, ((char)resultCode).ToString ());}return resultStringBuilder.ToString ();}}

0 0
原创粉丝点击