Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

GB2312 to UTF8 - Charcter encoding

$
0
0
hello,

I wanted to convert GB2312 (chinese) character encoding to UTF8. I will describe the problem as mentioned below and also let me know as to where I am going wrong in understanding the character encoding (source code also included).

The Subject headers of an email contain the following
Eg1:
=?GB2312?B?MzE2Njg3OTU4o6zA67K7v6q1xM/6Y8rb?=
Eg2:
=?utf-8?B?56ym54+C6bmm?=

where the format is :
=?CharSet?B/Q?Base64_encoded_string?=

When it comes to displaying UTF8 or GB2312 *individually* in different emails is not a problem, however when I want to display both these character-encodings , only one of them will get displayed.

This can be achieved by defining the charset in the email-msg body.

Content-Type: text/html;
charset="UTF-8"
OR
Content-Type: text/html;
charset="GB2312"



If all goes well you can view chinese characters.

Base64_Decode(""MzE2Njg3OTU4o6zA67K7v6q1xM/6Y8rb)

output:
MzE2Njg3OTU4o6zA67K7v6q1xM/6Y8rb = 316687958£¬Àë²»¿ªµÄÏúcÊÛ


Attached File  mail3.7z   828bytes   1 downloads Save the mentioned .7z and extract the .eml file and open this file in your fav. email-client

The code I am using is as follows and the output when replaced in the eml file doesnt give me any chinese characters .

[ autoit ]      
#Include $hFile=FileOpen('utf_t.txt',256+2) $sText = '316687958£¬Àë²»¿ªµÄÏúcÊÛ' FileWrite($hFile,_ConvertAnsiToUtf8($sText)) FileClose($hFile) Func _ConvertAnsiToUtf8($sText) Local $tUnicode = _WinAPI_MultiByteToWideChar($sText) If @error Then Return SetError(@error, 0, "") Local $sUtf8 =_WinAPI_WideCharToMultiByte(DllStructGetPtr($tUnicode), 65001) If @error Then Return SetError(@error, 0, "") Return SetError(0, 0, $sUtf8) EndFunc ;==>_ConvertAnsiToUtf8

Thanks in advance.

Regards
Del.

[UPDATE]
After searching found this:
http://hi.baidu.com/qianyiyidu/item/579ee4a1f6ca1b3e030a4df0


//GB2312到UTF-8的转换
static int GB2312ToUtf8(const char* gb2312, char* utf8)
{
int len = MultiByteToWideChar(CP_ACP, 0, gb2312, -1, NULL, 0);
wchar_t* wstr = new wchar_t[len+1];
memset(wstr, 0, len+1);
MultiByteToWideChar(CP_ACP, 0, gb2312, -1, wstr, len);
len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
utf8 = new char[len+1];
memset(utf8, 0, len+1);
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, utf8, len, NULL, NULL);
if(wstr) delete[] wstr;
return len;
}

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>