code
using System.Collections.Generic;
using UnityEngine;
public class ReplaceStr : MonoBehaviour
{
//字典中存储 需要替换的对应字符
public Dictionary<string, string> StrDict = new Dictionary<string, string>();
void Start()
{
//字典添加需要更改的字符
StrDict.Add("RW", "R<size=5>w</size>");
StrDict.Add("PR", "pr"); ;
Debug.Log(ReplaceString("RW_AS_PR_PR_RW"));
}
//替换方法
public string ReplaceString(string str)
{
foreach (KeyValuePair <string,string> ky in StrDict)
{
if (str.Contains(ky.Key))
{
str = str.Replace(ky.Key, ky.Value);
}
}
return str;
}
}