转换特殊字符正常 [英] Convert special characters to normal

查看:140
本文介绍了转换特殊字符正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种方法来特殊字符转换如下:

I need a way to convert special characters like this:

Helloæ

要普通字符。所以,这个词将结束是 Helloae 。到目前为止,我已经试过 HttpUtility.De code ,或将UTF8转换为win1252的方法,但是毫无效果。有什么简单和通用,会做这份工作吗?

To normal characters. So this word would end up being Helloae. So far I have tried HttpUtility.Decode, or a method that would convert UTF8 to win1252, but nothing worked. Is there something simple and generic that would do this job?

感谢您。

修改

我曾尝试使用实施岗位这里OC这两个方法。这里的方法:

I have tried implementing those two methods using posts here on OC. Here's the methods:

public static string ConvertUTF8ToWin1252(string _source)
{
    Encoding utf8 = new UTF8Encoding();
    Encoding win1252 = Encoding.GetEncoding(1252);

    byte[] input = _source.ToUTF8ByteArray();
    byte[] output = Encoding.Convert(utf8, win1252, input);

    return win1252.GetString(output);
}

// It should be noted that this method is expecting UTF-8 input only,
// so you probably should give it a more fitting name.
private static byte[] ToUTF8ByteArray(this string _str)
{
    Encoding encoding = new UTF8Encoding();
    return encoding.GetBytes(_str);
}

但它并没有奏效。字符串保持相同的方式

But it did not worked. The string remains the same way.

推荐答案

请参阅: .NET是否音译库是否存在?

Unide codeSharpFork

用法:

var result = "Helloæ".Unidecode();
Console.WriteLine(result) // Prints Helloae

这篇关于转换特殊字符正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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