将UTF8字符串解码为拉丁文 [英] Decode UTF8 String to Latin

查看:124
本文介绍了将UTF8字符串解码为拉丁文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将UTF8字符串转换为拉丁字符。

I am trying to transform a UTF8 string to Latin characters.

以下是我如何实现此目标的示例:

Here's a example of how I am trying to achieve this:

string sUnicode ="Peneda-Gerês";
string result = Encoding.Unicode.GetString(Encoding.Convert(Encoding.UTF8, Encoding.Unicode, Encoding.UTF8.GetBytes(sUnicode)));

MessageBox.Show(result);

字符串返回是否相同?没变化?

The string return is the same? No change?

我想念什么?

如果我转到此站点

http://software.hixie.ch/utilities/cgi/unicode-decoder/utf8-decoder

并将相同的文本正确解码为Peneda-Gerês;

and put the same text, it gets decode correctly to "Peneda-Gerês";

推荐答案

您的源字符串在ISO-8859-1中

Your source string is in ISO-8859-1

运行此命令并选择正确的编码器:

Run this and pick the correct encoder:

 string sUnicode = "Peneda-Gerês";
 foreach (var enc in Encoding.GetEncodings())
 {
    Console.WriteLine("{0} {1}"
        , Encoding.UTF8.GetString(enc.GetEncoding().GetBytes(sUnicode))
        , enc.Name);
 }

或要出现在以下位置:

string result = Encoding.UTF8.GetString(
     Encoding.GetEncoding("ISO-8859-1").GetBytes(sUnicode));

这篇关于将UTF8字符串解码为拉丁文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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