Unicode 到 ASCII,带有 umlats 的字符翻译
Unicode to ASCII with character translations for umlats
我有一个发送 unicode 输入文件的客户端,只需要 return 中的 ASCII 编码文件 - 为什么不重要。
有谁知道将 unicode 字符串转换为最接近的 ASCII 字符串的例程?我正在寻找将常见的 Unicode 字符(如“ä”)替换为最佳 ASCII 表示形式。
例如:'ä' -> 'a'
数据驻留在 SQL 服务器中,但我也可以在 C# 中作为下游机制或 CLR 过程工作。
只需遍历字符串即可。为每个角色做一个切换:
switch(inputCharacter)
{
case 'ä':
outputString = "ae";
break;
case 'ö':
outputString = "oe";
break;
...
(这些翻译在只有 ASCII 的德语中很常见)
然后将所有 outputString 与 StringBuilder 组合。
我认为你的意思是将 ASCII 扩展为 ASCII
只是一个简单的字典
Dictionary<char, char> trans = new Dictionary<char, char>() {...}
StringBuilder sb = new StringBuilder();
foreach (char c in string.ToCharArray)
{
if((Int)c <= 127)
sb.Append(c);
else
sbAppend(trans[c]);
}
string ascii = sb.ToString();
我有一个发送 unicode 输入文件的客户端,只需要 return 中的 ASCII 编码文件 - 为什么不重要。
有谁知道将 unicode 字符串转换为最接近的 ASCII 字符串的例程?我正在寻找将常见的 Unicode 字符(如“ä”)替换为最佳 ASCII 表示形式。
例如:'ä' -> 'a'
数据驻留在 SQL 服务器中,但我也可以在 C# 中作为下游机制或 CLR 过程工作。
只需遍历字符串即可。为每个角色做一个切换:
switch(inputCharacter)
{
case 'ä':
outputString = "ae";
break;
case 'ö':
outputString = "oe";
break;
...
(这些翻译在只有 ASCII 的德语中很常见)
然后将所有 outputString 与 StringBuilder 组合。
我认为你的意思是将 ASCII 扩展为 ASCII
只是一个简单的字典
Dictionary<char, char> trans = new Dictionary<char, char>() {...}
StringBuilder sb = new StringBuilder();
foreach (char c in string.ToCharArray)
{
if((Int)c <= 127)
sb.Append(c);
else
sbAppend(trans[c]);
}
string ascii = sb.ToString();