Jump to content
Sign in to follow this  
Cappuccino

How can I convert some words into UTF-8

Recommended Posts

Cappuccino

hi all, i have to encode some Chinese/Japanese words to the UTF-8 format in order to do a post action in IE, just like when we search a word "非常" (a chinese words means "very") in google, the browser will convert it to UTF-8 charactor "%E9%9D%9E%E5%B8%B8" and send it as a post data to the server. and in my case, i want to post some data to the page http://www.excite.co.jp/world/chinese (i'm making a online chinese/japanese translator for my girl friend :"> ), and then i'll receive a page contained the info i need. after analyzing the page, i could get the translated words. but the post data must be UTF-8, i don't know how to convert my words to that format, could anyone can any suggestion?

i have searched this forum, and there's a topic about this, it contain these codes:

Func URLEscape($text)
    $newtext=''
    For $x=1 To StringLen($text)
        $char=StringMid($text,$x,1)
        If StringRegExp($char,'\A|\.',0) Then
            $newchar=$char
        Else
            $newchar="%"&Hex(Asc($char),2)
        EndIf
        $newtext=$newtext&$newchar
    Next
    Return $newtext
EndFunc

in my test, if i input the english charctor, it works ok. but when i input the chinese charctor, this function's return value with GBK format instead of UTF-8.

Thanks.

Edited by Cappuccino

Share this post


Link to post
Share on other sites
Cappuccino

i have got a VBS to convert the charctor. it is below,

Function chinese2unicode(Str) 
  dim i 
  dim Str_one 
  dim Str_unicode 
  for i=1 to len(Str) 
    Str_one=Mid(Str,i,1) 
    Str_unicode=Str_unicode&chr(38) 
    Str_unicode=Str_unicode&chr(35) 
    Str_unicode=Str_unicode&chr(120) 
    Str_unicode=Str_unicode& Hex(ascw(Str_one)) 
    Str_unicode=Str_unicode&chr(59) 
  next 
  WScript.Echo Str_unicode
end function

but the return value of a word "非常" is "非常", not the value "%E9%9D%9E%E5%B8%B8" i mentioned. can any help? :whistle:

Share this post


Link to post
Share on other sites
Taiwanese

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×