从高到低 [英] high ascii to low ascii

查看:80
本文介绍了从高到低的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有没有一种算法可以将高ASCII码转换为低ASCII码.例如:我想将ù转换为u,将û转换为u,将ò转换为o,将Ä转换为A,等等.

我之所以这样问,是因为我不想将每个特殊字符都硬编码为等效字符.

grtz,
Wannes

Hi,

is there an algorithm which converts high ascii codes to low ascii codes. For example: I want to convert ù to u, û to u, ò to o, Ä to A, etc..

I just ask this because i don''t feel like hard coding each special char to his equivalent.

grtz,
Wannes

推荐答案

我是使用google找到的:
I found this using google:
public static string RemoveDiacritics(string s)
{
    string normalizedString = s.Normalize(NormalizationForm.FormD);
    StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i < normalizedString.Length; i++)
    {
        char c = normalizedString[i];
        if (CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark)
            stringBuilder.Append(c);
    }
    return stringBuilder.ToString();
}


如果您需要一种非常通用的方法(不使用框架函数等),请查看正在使用的代码表和
得到您的字符的数值,然后加上/减去适当的
数字,最后从该结果值中取回字符.

在ASCII中:A是65,而a是97.因此,只需在
中添加/减去32 字符数值,您很高兴
If you need a very generic approach (without the use of framework functions etc.), take a look at the code table you''re using and
get your chars'' numeric value, then add/subtract the appropiate
number and finally get the char back from that result value.

In ASCII: A is 65 while a is 97. So just add/subtract 32 from the
chars numeric value and you''re good to go


我看到您想用对应的普通字符替换带重音符号的字符.为此,您必须分别对待它们.

您可以使用String.ToLower()String.ToUpper()并分别处理重音字符,也可以使用 Dictionary( TKey,TValue类) [ ^ ]
I see that you want to replace accented characters with the correspondant plain ones. To do it you have to treat each of them separately.

You can use String.ToLower() and String.ToUpper() and treat the accented characters separately, or you can use the Dictionary(TKey, TValue Class)[^]


这篇关于从高到低的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆