Chinese character encoding of URL in Delphi

Source: Internet
Author: User
Chinese character encoding of URL in Delphi

Show. asp? Sort = All & sortlevel = 1 & gorq = for & n = 5 & sitename = All & IMG = Yes & imgfile =/images/dot_g.gif

In this form, Baidu queries are converted to gb2312 encoding. Each Chinese Character corresponds to 2% XX, but on Google, each Chinese Character corresponds to three % XX, which adopts unicode encoding.

In delphi2010, due to the introduction of Unicode, the default value is 3% XX, which leads to a problem in my program. After searching for half a day, each function can implement automatic detection of full URL encoding, so I wrote one and shared it with you:

Uses

Httpapp;

Function urlencode (aurl: string): string;
VaR
I: integer;
Stmp, tstmp: string;
Begin
Result: = aurl;
If length (aurl)> 0 then
Begin
For I: = 1 to length (aurl) Do
Begin
If INTEGER (ord (aurl [I])> 255 then
Begin
Stmp: = copy (aurl, I, 1 );
Tstmp: = httpencode (stmp );
Result: = stringreplace (result, stmp, tstmp, []);
End;
End;
End;
End;

 

Usage:

URL: = urlencode (URL );

Then, the Chinese characters in the URL are automatically converted to the % XX encoding of gb2312.

 

Refer:

Http://ifso.iteye.com/blog/1513438

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.