效率比较低,建议写io的的时候,进行副本存储,读的时候就不用替换了:
namespace tools
{
/// <summary>
/// 简繁转化
/// </summary>
public static class ChineseStringUtility
{
private static string strSimplifiedDictionary = SimplifiedDictionary();
private static string strTraditionalDictionary = TraditionalDictionary();
/// <summary>
/// 简体转繁体
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string SimToTra(string str)
{
string strResult = "";
int nIndex = -1;
for (int i = 0; i < str.Length; i++)
{
nIndex = strSimplifiedDictionary.IndexOf(str[i]);
if (nIndex >= 0)
{
strResult += strTraditionalDictionary[nIndex];
}
else
{
strResult += str[i];
}
}
return strResult;
}
/// <summary>
/// 繁体转简体
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string TraToSim(string str)
{
string strResult = "";
int nIndex = -1;
for (int i = 0; i < str.Length; i++)
{
nIndex = strTraditionalDictionary.IndexOf(str[i]);
if (nIndex >= 0)
{
strResult += strSimplifiedDictionary[nIndex];
}
else
{
strResult += str[i];
}
}
retu