Several confusing encoding Functions

Source: Internet
Author: User

1. Baidu coding and decoding

Enter "Peng Chenggang" in Baidu and click "% C5 % ed % B3 % C9 % B8 % D5" in the URL bar after the search. How is this encoded, how to decode. the following two paragraphsCodeThese two questions can be solved:

// Baidu code

Console. writeline (system. Web. httputility. urlencode ("Peng Chenggang", system. Text. unicodeencoding. getencoding ("gb2312"). toupper ());

// Baidu Decoding

Console. writeline (system. web. httputility. urldecode ("% C5 % ed % B3 % C9 % B8 % D5", system. text. unicodeencoding. getencoding ("gb2312 ")));

2. html encoding and decoding Functions

// Html Encoding

System. Web. httputility. htmlencode (string); server. htmlencode (string)

// HTML Decoding

System. Web. httputility. htmldecode (string); server. htmldecode (string)

Decoding HTML tags. Non-HTML tags are not decoded, for example

--->

3. url encoding and decoding

// URL Encoding

System. Web. httputility. urlencode (string); server. urlencode (string );

System. Web. httputility. urlpathencode (string); server. urlpathencode (string );

Urlencode and urlpathencode are different in terms of encoding.

For example, urlencode encodes the entire URL (http://www.zzcn.net/full code)

Urlpathencode encode the content after http: // (www.zzcn.net)

// URL Decoding

System. Web. httputility. urldecode (string); server. urldecode (string );

4. UTF-8, gb2312 Conversion

UTF-8> gb2312

String content = "Peng Chenggang ";

Byte [] conby = encoding. utf8.getbytes (content );

Content = encoding. getencoding ("gb2312"). getstring (conby );

Console. writeline (content );

I will not write it on the contrary. I hope to have a better understanding of you. If you have any questions, please correct them. Thank you.

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.