Converting Chinese characters to UTF-8
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 (1, 120)
Str_unicode = str_unicode & hex (ASCW (str_one ))
Str_unicode = str_unicode & CHR (59)
Next
Response. Write str_unicode
End Function
UTF-8 to gb2312
Function utf2gb (utfstr)
For dig = 1 to Len (utfstr)
If mid (utfstr, dig, 1) = "%" then
If Len (utfstr)> = dig + 8 then
Gbstr = gbstr & convchinese (mid (utfstr, dig, 9 ))
Dig = dig + 8
Else
Gbstr = gbstr & Mid (utfstr, dig, 1)
End if
Else
Gbstr = gbstr & Mid (utfstr, dig, 1)
End if
Next
Utf2gb = gbstr
End Function
Function convchinese (X)
A = Split (mid (x, 2), "% ")
I = 0
J = 0
For I = 0 to ubound ()
A (I) = c16to2 (A (I ))
Next
For I = 0 to ubound (a)-1
Digs = instr (a (I), "0 ")
Unicode = ""
For j = 1 to digs-1
If j = 1 then
A (I) = right (a (I), Len (A (I)-Digs)
Unicode = Unicode & A (I)
Else
I = I + 1
A (I) = right (a (I), Len (A (I)-2)
Unicode = Unicode & A (I)
End if
Next
If Len (c2to16 (UNICODE) = 4 then
Convchinese = convchinese & chrw (INT ("& H" & c2to16 (UNICODE )))
Else
Convchinese = convchinese & CHR (INT ("& H" & c2to16 (UNICODE )))
End if
Next
End Function
Function c2to16 (X)
I = 1
For I = 1 to Len (x) Step 4
C2to16 = c2to16 & hex (c2to10 (mid (X, I, 4 )))
Next
End Function
Function c2to10 (X)
C2to10 = 0
If X = "0" then exit function
I = 0
For I = 0 to Len (x)-1
If mid (x, Len (x)-I, 1) = "1" then c2to10 = c2to10 + 2 ^ (I)
Next
End Function
Function c16to2 (X)
I = 0
For I = 1 to Len (TRIM (x ))
Tempstr = c10to2 (CINT ("& H" & Mid (X, I, 1 ))))
Do While Len (tempstr) <4
Tempstr = "0" & tempstr
Loop
C16to2 = c16to2 & tempstr
Next
End Function
Function c10to2 (X)
Mysign = SGN (X)
X = ABS (X)
Digs = 1
Do
If x <2 ^ digs then
Exit do
Else
Digs = digs + 1
End if
Loop
Tempnum = x
I = 0
For I = digs to 1 step-1
If tempnum> = 2 ^ (I-1) then
Tempnum = tempnum-2 ^ (I-1)
C10to2 = c10to2 & "1"
Else
C10to2 = c10to2 & "0"
End if
Next
If mysign =-1 then c10to2 = "-" & c10to2
End Function