Use APIs for simplified and traditional Conversion

Source: Internet
Author: User
1. Enter big5 characters and return the simplified GB characters
//---------------------------------------------------------------------------
// Function input: big5 characters, returns the simplified GB characters
//---------------------------------------------------------------------------
Ansistring _ fastcall big2gb (ansistring SBIG)
{
Char * pszbig5 = NULL; // big5 encoded character
Wchar_t * wszunicode = NULL; // Unicode-encoded character
Char * pszgbt = NULL; // traditional characters encoded in GB
Char * pszgbs = NULL; // Simplified characters in GB encoding
Ansistring SGB; // The returned string.
Int ilen = 0; // number of characters to be converted

Pszbig5 = SBIG. c_str (); // read the character parameters to be converted

// Calculate the number of characters to convert
Ilen = multibytetowidechar (950, 0, pszbig5,-1, null, 0 );
// Allocate memory to wszunicode
Wszunicode = new wchar_t [ilen + 1];
// Convert the big5 code to the Unicode code. The API function multibytetowidechar is used.
Multibytetowidechar (950, 0, pszbig5,-1, wszunicode, ilen );

// Calculate the number of characters to convert
Ilen = widechartomultibyte (936, 0, (pwstr) wszunicode,-1, null, 0, null, null );
// Allocate memory to pszgbt
Pszgbt = new char [ilen + 1];
// Allocate memory to pszgbs
Pszgbs = new char [ilen + 1];
// Convert the Unicode code to the traditional GB code. Use the API function widechartomultibyte.
Widechartomultibyte (936, 0, (pwstr) wszunicode,-1, pszgbt, ilen, null, null );

// Convert the Gbit/s to simplified Gbit/s. Use the lcmapstring API
Lcmapstring (0x0804, lcmap_simplified_chinese, pszgbt,-1, pszgbs, ilen );

// Return the Simplified characters of the GB code
SGB = pszgbs;

// Release the memory
Delete [] wszunicode;
Delete [] pszgbt;
Delete [] pszgbs;

Return SGB;
}
2. Enter the GB character and return the big5 character
//---------------------------------------------------------------------------
// The function inputs a gb character and returns a big5 character.
//---------------------------------------------------------------------------
Ansistring _ fastcall gb2big (ansistring SGB)
{
Char * pszgbt = NULL; // traditional characters encoded in GB ***

 

 

***

Char * pszgbs = NULL; // Simplified characters in GB encoding
Wchar_t * wszunicode = NULL; // Unicode-encoded character
Char * pszbig5 = NULL; // big5 encoded character
Ansistring sbig5; // returned string
Int ilen = 0; // number of characters to be converted

Pszgbs = SGB. c_str (); // read the character parameters to be converted

// Calculate the number of characters to convert
Ilen = multibytetowidechar (936, 0, pszgbs,-1, null, 0 );

// Allocate memory to pszgbt
Pszgbt = new char [ilen * 2 + 1];
// Convert the Gbit/s to the traditional Gbit/s. Use the lcmapstring API
Lcmapstring (0x0804, lcmap_traditional_chinese, pszgbs,-1, pszgbt, ilen * 2 );

// Allocate memory to wszunicode
Wszunicode = new wchar_t [ilen + 1];
// Convert the GB code to the Unicode code. The API function multibytetowidechar is used.
Multibytetowidechar (936, 0, pszgbt,-1, wszunicode, ilen );

// Calculate the number of characters to convert
Ilen = widechartomultibyte (950, 0, (pwstr) wszunicode,-1, null, 0, null, null)

 

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.