using UnityEngine;
using System.Collections;
using System.Text;
using System.Text.RegularExpressions;
public class TTTTTTst : MonoBehaviour
{
// Use this for initialization
void 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 ();
}
}
unity C# 含有实体字符的字符串转换成正常的字符串
最新推荐文章于 2024-07-11 11:54:51 发布