Returns the UTF-8 encoding in the page search URL to Chinese Characters

Source: Internet
Author: User

When browsing the page, you can see that the URL in the address bar rarely displays Chinese characters, all of which are symbols and English letters, this explains to some extent why Chinese software is not developed (to be in line with foreign systems, character conversion is required, which is a headache, A lot of time is often spent on character format conversion, cup ).

 

Now we are working on a character conversion applet that restores the encoding in the HTTP request to Chinese characters. If you are not familiar with this, please refer to this article. The analysis here is in place. After searching on csdn for a long time, I only found that utf8 was converted into Chinese characters, but gb2312 was not converted into Chinese characters. I am very depressed. I don't know if gb2312 can be converted, which is a headache.

 

The utf8 Conversion Program is as follows:

# Include <stdio. h> # include <stdlib. h> # include <iostream> # include <windows. h> using namespace STD; int main () {// char s [] = "% E4 % B8 % ad % E5 % 9B % BD % E9 % 93% B6 % E8 % a1 % 8C % E6 % ad % a6 % E6 % B1 % 89% E5 % B8 % 82% E9 % 87% E8 % 9e % 8d % E6 % B8 % af % E9 % 91% B6 % E8 % a1 % 8C "; char s [] = "% E6 % B1 % 89% E5 % ad % 97% E7 % BC % 96% E7 % A0 % 81"; int Len = strlen (s ); char * temps = new char [Len + 1]; temps [Len] = '\ 0'; int temps_pos = 0; int I; // remove the % for (I = 0; I <L En; ++ I) {If (s [I]! = '%') {Temps [temps_pos] = s [I]; temps_pos ++;} temps [temps_pos] = '\ 0'; cout <temps <Endl; int temps_len = strlen (temps); int utf8len = temps_len/2; char * utf8str = new char [utf8len + 1]; utf8str [utf8len] = '\ 0 '; // convert the character to a number to obtain the real utf8 string for (I = 0; I <utf8len * 2;) {char Convert [3] = {0 }; convert [0] = temps [I ++]; Convert [1] = temps [I ++]; char * end; int tempint = strtol (convert, & end, 16); utf8str [I/2-1] = tempint;} // convert UTF16 int wcslen =: multibytetowidechar (cp_utf8, null, utf8str, utf8len, null, 0); wchar_t * wszstring = new wchar_t [wcslen + 1];: multibytetowidechar (cp_utf8, null, utf8str, utf8len, wszstring, wcslen ); wszstring [wcslen] = L' \ 0'; // you can specify the STD: wcout. imbue (STD: locale ("CHS"); wcout <wszstring <Endl; Delete [] temps; Delete [] utf8str; Delete [] wszstring; return 0 ;}

 

When will a program for converting gb2312 to Chinese characters appear, provided that it is written in C/C ++.

 

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.