高度相关的问题是在这里: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