高度相關的問題是在這裏:Replacing unicode punctuation with ASCII approximations
雖然回答有不足,它給了我一個想法。我可以將基本多語言平面(0)中的每個Unicode代碼點映射到等效的ASCII字符(如果存在)。以下C#代碼將幫助您創建一個HTML表單,您可以在其中鍵入每個值的替換字符。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.IO;
namespace UnicodeCharacterCategorizer
{
class Program
{
static void Main(string[] args)
{
string output_filename = "output.htm"; //set a filename if not specifying one through the command line
Dictionary<UnicodeCategory,List<char>> category_character_sets = new Dictionary<UnicodeCategory,List<char>>();
foreach (UnicodeCategory c in Enum.GetValues(typeof(UnicodeCategory)))
category_character_sets.Add(c, new List<char>());
for (int i = 0; i <= 0xFFFF; i++)
{
if (i >= 0xD800 && i <= 0xDFFF) continue; //Skip ranges reserved for high/low surrogate pairs.
char c = (char)i;
UnicodeCategory category = char.GetUnicodeCategory(c);
category_character_sets[category].Add(c);
}
StringBuilder file_data = new StringBuilder(@"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd""><html xmlns=""http://www.w3.org/1999/xhtml""><head><title>Unicode Category Character Sets</title><style>.categoryblock{border:3px solid black;margin-bottom:10px;padding:5px;} .characterblock{display:inline-block;border:1px solid grey;padding:5px;margin-right:5px;} .character{display:inline-block;font-weight:bold;background-color:#ffeeee} .numericvalue{color:blue;}</style></head><body><form id=""charactermap"">");
foreach (KeyValuePair<UnicodeCategory,List<char>> entry in category_character_sets)
{
file_data.Append(@"<div class=""categoryblock""><h1>" + entry.Key.ToString() + ":</h1><br />");
foreach (char c in entry.Value)
{
string hex_value = ((int)c).ToString("x");
file_data.Append(@"<div class=""characterblock""><span class=""character"">&#x" + hex_value + @";<br /><span class=""numericvalue"">" + hex_value + @"</span><br /><input type=""text"" name=""r_" + hex_value + @""" /></div>");
}
file_data.Append("</div>");
}
file_data.Append("</form></body></html>");
File.WriteAllText(output_filename, file_data.ToString(), Encoding.Unicode);
}
}
}
具體而言,代碼將產生含有在BMP中的所有字符,與「R_」(R爲「替換值」)爲前綴的十六進制值命名的輸入文本框沿着一個HTML表格。如果移植到ASP.NET頁面,額外的代碼可以被寫入到預填充替代值儘可能:如果已經ASCII
- 自己的價值,或者
- 使用Unicode標準化FormD或FormKD分解等價物,或
- 爲一整類單個ASCII值(即所有的「標點初始」與ASCII雙引號字符)
然後你可以去通過手動做出調整,它可能止跌只要你想,就花不了多久。只有64512個代碼點,並且整個類別的大塊可能被解僱爲「甚至不接近任何ASCII」。所以,我要建立這個地圖和功能。
另請參閱http:// stackoverflow。com/questions/138449/how-to-convert-a-unicode-character-to-its-ascii-equivalent – 2011-04-13 20:23:07
該鏈接與我的問題無關,以及所有評論與我發佈的鏈接相關的地方在哪裏?這個問題看起來很相似,但它確實在問如何編碼一個特定的代碼頁(因此GetEncoding.GetBytes),而不是將Unicode Unicode字符轉換爲等效的ASCII字符,這完全與編碼無關。我感興趣的是像WordPress的函數remove_accents(http://stackoverflow.com/questions/138449/how-to-convert-a-unicode-character-to-its-ascii-equivalent/1748412#1748412)可憐的人下了船 - IMO投票給了一個好的答案,雖然有點缺陷。 – Triynko 2011-04-13 21:06:31
現在這是高度相關性>> http://stackoverflow.com/questions/4808967/replacing-unicode-punctuation-with-ascii-approximations – Triynko 2011-04-14 16:48:32