Use C # to encode and decode Google and Baidu Chinese keywords

Source: Internet
Author: User
The keyword encoding of Google and Baidu is different. It seems that Google is UTF-8 and Baidu is gb2312. There are many methods to solve the encoding. The following three methods are listed:
Uri. unescapedatastring (); It can be used to decode most of Google's Chinese keywords, but encoding that cannot be decoded will cause garbled characters and cannot be used to decrypt hundreds of keywords.
Microsoft. JScript. globalobject. decodeuri (); Most of the Chinese keywords can be decoded, but a small number of Chinese keywords cannot be decoded. Microsoft. JScript references are required.
Httputility. urldecode (STR, encoding. Default ); You can extract hundred-degree keyword encoding. you can decode the above two methods and cannot decode the Google Keyword. The system. Web reference is required.
To solve the problem of Google and Baidu keyword decoding simultaneously, you can use the following methods:
// STR is the encoded Google or Baidu keyword
Try
{
... Microsoft. JScript. globalobject. decodeuri (Str. Trim ())...
}
Catch {
... Httputility. urldecode (STR, encoding. Default )...
}

When Microsoft. JScript. globalobject. decodeuri () cannot be decoded, an error is returned. After capturing the error, you can use httputility. urldecode to decode it.

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.