GB2312 and UTF8 reciprocal conversion function __ function

Source: Internet
Author: User

Converts GB2312 to UTF8 string Updatemodule::gb2132toutf8 (String strsrc) {string result; WCHAR *wstrsrc = NULL; char *szres = NULL; int i; GB2312 Convert to Unicode i = MultiByteToWideChar (CP_ACP, 0, Strsrc.c_str (),-1, NULL, 0); WSTRSRC = new Wchar[i+1]; MultiByteToWideChar (CP_ACP, 0, Strsrc.c_str (),-1, WSTRSRC, i); Unicode converts to UTF8 i = WideCharToMultiByte (Cp_utf8, 0, Wstrsrc,-1, NULL, 0, NULL, NULL); Szres = new Char[i+1]; WideCharToMultiByte (Cp_utf8, 0, Wstrsrc,-1, szres, I, NULL, NULL); result = string (szres); if (wstrsrc!= null) {delete []wstrsrc; wstrsrc = null;} if (Szres!= NULL) {delete []szres; szres = null;} return res Ult }                                                              &nbspReciprocal conversion functions of;          GB2312 and UTF8

Converts UTF8 to GB2312 string utf8togb2132 (String strsrc) {string result; WCHAR *wstrsrc = NULL; char *szres = NULL; int i; UTF8 Convert to Unicode i = MultiByteToWideChar (Cp_utf8, 0, Strsrc.c_str (),-1, NULL, 0); WSTRSRC = new Wchar[i+1]; MultiByteToWideChar (Cp_utf8, 0, Strsrc.c_str (),-1, WSTRSRC, i); Unicode converts to GB2312 i = WideCharToMultiByte (CP_ACP, 0, Wstrsrc,-1, NULL, 0, NULL, NULL); Szres = new Char[i+1]; WideCharToMultiByte (CP_ACP, 0, Wstrsrc,-1, szres, I, NULL, NULL); result = string (szres); if (wstrsrc!= null) {delete []wstrsrc; wstrsrc = null;} if (Szres!= NULL) {delete []szres; szres = null;} return res Ult }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.