WP8 implements the utf8 to gb2312 transcoding Function

Source: Internet
Author: User

Directly use example: http://www.abc.php? Name = Chinese character, called by the client. garbled characters will appear after modification on the server,

Windows Phone does not support gb2312 directly. After a lot of analysis and verification, it is found that everything goes through "Conversion from Chinese characters to hexadecimal,

The Code is as follows:

String text = "Chinese character"; string url1 = "http://www.abc.php? Name = "; string url2 = url1 + utf8togb2312 (text, true ); /// <summary> /// convert Chinese characters to hexadecimal notation /// </Summary> /// <Param name = "argstrutf8"> </param> // /<Param name = "arguseparator"> whether to use % to separate Chinese characters </param> // <returns> </returns> Public static string utf8togb2312 (string argstrutf8, bool arguseseparator = true) {If (argstrutf8.length % 2 )! = 0) {argstrutf8 + = ""; // space} system. text. encoding CHS = dbcsencoding. getdbcsencoding ("gb2312"); // system. text. encoding. getencoding (charset); byte [] bytes = chs. getbytes (argstrutf8); string STR = arguseseparator? "%": ""; For (INT I = 0; I <bytes. length; I ++) {STR + = string. format ("{0: x}", bytes [I]); If (arguseseparator & (I! = Bytes. Length-1) {STR + = string. Format ("{0}", "%") ;}} return Str. toupper ();}

Http://wp.662p.com/thread-8250-1-1.html

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.