看到黑暗有一個關於中文難字的繁簡轉換處理的文章, 先記錄部份在這裡.
http://blog.darkthread.net/post-2015-03-06-strconv-half-full-width-notes.aspx
var ncrString = toNCR("黑暗執行緒犇ABC123");
Debug.WriteLine(ncrString); //黑暗執行緒犇ABC123
var convString = Microsoft.VisualBasic.Strings.StrConv(
ncrString, Microsoft.VisualBasic.VbStrConv.Narrow, 1028);
Debug.WriteLine(convString); //黑暗执行绪犇ABC123
var resultString = fromNCR(convString);
Debug.WriteLine(resultString); //黑暗执行绪犇ABC123
static string toNCR(string input)
{
StringBuilder sb = new StringBuilder();
Encoding big5 = Encoding.GetEncoding("big5");
foreach (char c in input)
{
//強迫轉碼成Big5,看會不會變成問號
string cInBig5 = big5.GetString(big5.GetBytes(new char[] {c}));
//原來不是問號,轉碼後變問號,判定為難字
if (c!='?' && cInBig5=="?")
sb.AppendFormat("&#{0};", Convert.ToInt32(c));
else
sb.Append(c);
}
return sb.ToString();
}
static string fromNCR(string input)
{
return Regex.Replace(input, "&#(?<ncr>\\d+?);", (m) =>
{
return Convert.ToChar(int.Parse(m.Groups["ncr"].Value)).ToString();
});
}