Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 May : Re: url encode to utf-8
| Subject: | Re: url encode to utf-8 |
| Posted by: | "ildg" (il..@163.com) |
| Date: | 25 May 2006 18:43:38 |
"Ian Stuart" <ian.stuart@chello.at> wrote:
>"ildg" <ildg@163.com> wrote in message
>news:44741f9a@newsgroups.borland.com...
>>
>> "Piotr Szturmaj" <gacek999@NOSPAM.tlen.pl> wrote:
>>>>>Utf8Encode()
>>>>
>>>> Thank you~
>>>> But it doesn't work at all.
>>>> when I pass a widestring to utf8encode, I get disordered codes.
>>>
>>>What do you mean by "disordered codes"? I'm using this function in my
>>>applications and it works well.
>>>
>>>
>>
>> It only works on English words. If non-Enlish words are contained, the
>> result will become unrecognizable, that's what I called "disordered
>> codes". But in java, I can get right result, no matter what I want to
>> encode.
>>
>> By the way, I was trying to encode Chinese words.
>
>The results will certainly be unrecognizable if viewed as a raw string. Each
>unicode character may become one, two or three characters when encoded to
>UTF8. Only the characters in the range 0-127 are preserved unencoded which
>will allow you to call UTF8Encode and then HttpEncode successfully. I
>suspect that the inspector tool you are using in JAVA understands the string
>is UTF8 and decodes it for you when you look at it. Delphi inspector does
>not decode it for viewing so you what looks like garbage. Nevertheless, the
>function does work.
>
>Regards
>Ian
>
>
I believe that the function does work.
But it's not what I want.
What I want is, I want to encode a string as "%xx%yy%zz%dd" format, that's what HttpEncode does. But, Http only encode it to
old format, I want it to encode as utf-8 format.
For example, I have a string named str that contains Chinese words. When I use HttpEncode(str), I get this result: %BA%BA%D7%D6+%D6%D0%CE%C4. But what I want is:
%E6%B1%89%E5%AD%97+%E4%B8%AD%E6%96%87.
They are quite different, and it's generated by UrlEncoder.Encode(str,"utf-8") in java. So I come here for help to find out if there's any delphi equivalent.
Thank you.