解码=?UTF-8?B'在C#...?=字符串 [英] Decode a =?utf-8?B?...?= string in C#
问题描述
我用 VS2010
, C#
用来阅读Gmail收件箱 IMAP
,它可以作为一个魅力,但我认为Unicode是不完全支持,因为我不能让波斯语字符串容易。
I use VS2010
, C#
to read gmail inbox using IMAP
, it works as a charm, but I think unicode is not fully supported as I cannot get Persian (Farsi) strings easily.
比如我有我的字符串:سلام
,但 IMAP
给我:???= UTF-的8B 2LPZhNin2YU =?=
。
For instance I have my string: سلام
, but IMAP
gives me: "=?utf-8?B?2LPZhNin2YU=?="
.
我怎样才能将其转换为原始字符串?从coverting UTF-8字符串任何提示?
How can I convert it to original string? any tips from coverting utf-8 to string?
感谢
推荐答案
让我们来看看的意思MIME编码:????
Let's have a look at the meaning of the MIME encoding:
=?utf-8?B?...something...?=
^ ^
| +--- The bytes are Base64 encoded
|
+---- The string is UTF-8 encoded
所以,解码此,取 ...什么...
你的字符串( 2LPZhNin2YU =
你的情况),然后
So, to decode this, take the ...something...
out of your string (2LPZhNin2YU=
in your case) and then
-
扭转Base64编码
reverse the Base64 encoding
var bytes = Convert.FromBase64String("2LPZhNin2YU=");
解释字节为UTF8字符串
interpret the bytes as a UTF8 string
var text = Encoding.UTF8.GetString(bytes);
文本。code>现在应包含所期望的结果。
text
should now contain the desired result.
这格式的描述可以在维基百科中找到:
A description of this format can be found in Wikipedia:
- http://en.wikipedia.org/wiki/MIME#Encoded-Word
这篇关于解码=?UTF-8?B'在C#...?=字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!