这是MIME的标示Encoded-WordSince RFC 2822, conforming message header names and values should be ASCII characters; values that contain non-ASCII data should use the MIME encoded-word syntax (RFC 2047) instead of a literal string. This syntax uses a string of ASCII characters indicating both the original character encoding (the "charset") and the content-transfer-encoding used to map the bytes of the charset into ASCII characters. The form is: "=?charset?encoding?encoded text?=". charset may be any character set registered with IANA. Typically it would be the same charset as the message body. encoding can be either "Q" denoting Q-encoding that is similar to the quoted-printable encoding, or "B" denoting base64 encoding. encoded text is the Q-encoded or base64-encoded text.来自Widipedia http://en.wikipedia.org/wiki/MIME
MjAxMtbQzuez1Mqyw7Q=Response.Write(Encoding.GetEncoding("gbk").GetString(Convert.FromBase64String("MjAxMtbQzuez1Mqyw7Q=")));
输出:2012中午吃什么
+1根据这个,可以知道这个字符串是经过包装的 Base64String,其中 "=?" 表示编码头,"?=" 表示编码结尾,"GBK?" 表示编码规则,"B?" 表示 base64。
The form is: "=?charset?encoding?encoded text?=".
charset may be any character set registered with IANA. Typically it would be the same charset as the message body.
encoding can be either "Q" denoting Q-encoding that is similar to the quoted-printable encoding, or "B" denoting base64 encoding.
encoded text is the Q-encoded or base64-encoded text.来自Widipedia
http://en.wikipedia.org/wiki/MIME
{
Match match = Regex.Match(base64, @"(?<=\?)[^?]+(?=\?=)");
return match.Value;
}
{
string code;
string base64 = MethedA("=?GBK?B?MjAxMtbQzuez1Mqyw7Q=?=", out code);
Response.Write(base64 + "<br/>");
Response.Write("字符集为:" + code);
} private static string MethedA(string base64, out string code)
{
Match match = Regex.Match(base64, @"=\?([^?]+)\?[bB]\?([^?]+)(?=\?=)");
code = match.Groups[1].Value;
return match.Groups[2].Value;
}
调用方法,获取标准base64字符串,以及字符集名称:
MjAxMtbQzuez1Mqyw7Q=
字符集为:GBK