从iso-8859-1转换为UTF-8 [英] Converting from iso-8859-1 to UTF-8

查看:194
本文介绍了从iso-8859-1转换为UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家早上好。



我正在编写一个C ++应用程序,它尝试使用POP3协议从邮箱中获取一些信息。我想要获取的信息包含法语字符,意味着强调的字符,如é,ç,à。我需要将这些信息存储在MySQL数据库中。要在屏幕上或文件中显示这些信息,我会得到奇怪的字符而不是强调的字符。

一个例子:

而不是得到:



Super ULaFertéGaucher:Démarrage



我得到:



Super U La Fert =?iso-8859-1?B?6SBHYXVjaGVyIDogTlJ2aXNpb24gMjAxMy0xMSA6IETp?= marrage



我可以从生成的信息中读取我的角色在iso-8859-1中编码,但我需要UTF-8。

有没有办法解码这些信息,或者为了得到正确的结果可能需要进行一些配置。

我不想使用任何非标准库(仅限Microsoft工具)。

备注:我使用的是Visual Studio 2010,Windows 8.我的应用程序是两个版本控制台CLR和MFC。



提前谢谢

Good morning everyone.

I am writing a C++ application which tries to get some information from a mail box using POP3 protocol. The information I am trying to get contains French characters, means accentuated characters like "é, ç, à". I need to store this information in a MySQL database. To display this information on the screen or in a file I get strange characters instead of the accentuated ones.
an example :
instead of getting:

"Super U La Ferté Gaucher : Démarrage"

I get:

"Super U La Fert=?iso-8859-1?B?6SBHYXVjaGVyIDogTlJ2aXNpb24gMjAxMy0xMSA6IETp?=marrage"

I can read from the generated information that my characters are coded in iso-8859-1, but I need them in UTF-8.
Is there any way to decode this information, or maybe some configuration that should be done to get the right result.
I don't want to use any non-standard libraries (only Microsoft tools).
Remarks: I am using Visual Studio 2010, Windows 8. My application is in two versions Console CLR and MFC.

Thank you in advance

推荐答案

消息根据<编码a href =https://www.ietf.org /rfc/rfc2047.txt\">RFC 2047 [ ^ ]。您的示例中的编码机制是 Base64 [ ^ ](由'B'表示)。



如果你不这样做想要使用额外的库,你必须编写自己的解析器来获取代码页和编码(对于Base64为'B'或对于quoted-printable为'Q')并对文本进行解码(有许多C / C ++源代码示例) net)。



获得解码后的文本后,使用 MultiByteToWideChar [ ^ ]传递相应的代码页码,最后使用 WideCharToMultiByte [ ^ ]。
The message is encoded according to RFC 2047[^]. The encoding mechanism from your example is Base64[^] (indicated by the 'B').

If you don't want to use an additional library, you must write your own parser to get the code page and encoding ('B' for Base64 or 'Q' for quoted-printable) and decode the text (there are many C/C++ source examples in the net).

Once you have the decoded text, convert it to Unicode using MultiByteToWideChar[^] passing the corresponding code page number, and finally convert the wide string to UTF-8 using WideCharToMultiByte[^].


这篇关于从iso-8859-1转换为UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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