[My major gains] C # winform implements URI encoding for Chinese characters!

Source: Internet
Author: User
Today, I spent a long time performing URI encoding and decoding operations. But I cannot get the desired result.
So I have referenced a lot Article , Two articles are recommended here:
Http://www.cnblogs.com/tishifu/archive/2006/03/01/340646.html
Http://www.cnblogs.com/TianFang/archive/2006/07/28/399842.html
Finally, based on the second article, I found a solution.
First, add a reference to system. Web. You may need to import system. Web. dll twice. Program Add a namespace reference to the set.
Next, refer to the following Code : 1 String Str1 = Textbox1.text;
2 String Str2 = System. Web. httputility. urlencode (str1, encoding. getencoding ( " Gb2312 " )); // Encode the string.
3 // String str2 = system. Web. httputility. urldecode (str1, encoding. getencoding ("gb2312 "));
4 // The preceding line of code is used to decode the URI-encoded string.
5 Textboxr. appendtext (str2 );

currently, I only know one of the above methods to correctly encode and decode them.
if you are not convinced, please try it. (the following URL provides the desired decoding and encoding results. For example, "new concept", the encoding I want is "% D0 % C2 % B8 % C5 % c4 % ee ").
http://www.haokucn.com/haocoolfj/onlinetools/aspcodetools/URLCode/URLDecoding.asp

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.