This article gives you some very useful code, which can be transferred in ASP. These include UTF8 GB2312 binary decimal code hexadecimal.
'UTF to GB --- Convert UTF8 encoding text to GB encoding text
Function UTF2GB (UTFSTR) for Dig = 1 to Len (UTFSTR)
'If UTF8 coding text starts with%, it will be converted
If MID (UTFSTR, DIG, 1) =% then
'UTF8 encoding text is greater than 8, then converted to Chinese characters
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
'UTF8 encoding text will be converted into Chinese characters
Function Convchinese (X)
A = split (mid (x, 2),%)
i = 0
j = 0
for i = 0 to ubound (A)
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 that
Convchinese = Convchinese & chrw (int (& h & c2TO16 (unicode))
else
Convchinese = Convchinese & CHR (int (& H & C2TO16 (Unicode))
end if
next
end function
'Binary code convert to hexadecimal code
Unction C2TO16 (x)
i = 1
for i = 1 to len (x) Step 4
C2TO16 = C2TO16 & HEX (C2TO10 (MID (X, I, 4)))
next
end function
'Binary code converts to decimal code
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
'Scripture code is converted to binary code
Function C16TO2 (x)
i = 0
for i = 1 to len (trim (x))
tempstr = C10TO2 (CINT (int (& h & mid (x, i, 1)))
Do While Len (Tempstr) <4
Tempstr = 0 & Tempstr
loop
C16TO2 = C16TO2 & Tempstr
next
end function
'Top code convert to binary code
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
'GB to UTF8-convert GB encoding text to UTF8 encoding text
Function Toutf8 (szinput)
Dim WCH, UCH, Szret
Dim x
DIM NASC, NASC2, NASC3
'If the input parameter is empty, the exit function
If szinput = then
TOUTF8 = szinput
Exit function
End if
'Start conversion
For x = 1 to len (szinput)
'Use the MID function to split GB encoding text
WCH = MID (szinput, x, 1)
'Use the ASCW function to return the Unicode character code of each GB encoded text
'Note: The ASC function returns an ANSI character code, pay attention to the difference
NASC = ASCW (WCH)
If nasc <0 THEN NASC = NASC + 65536
If (NASC and & HFF80) = 0 THEN
szret = szret & WCH
Else
If (NASC and & HF000) = 0 then
uch = % & hex ((NASC / 2 ^ 6)) or & HC0 & hex (NASC and & H3F or & H80)
szret = szret & uch
Else
'GB encoding text Unicode character code is used between 0800 -FFFF
uch = % & hex ((NASC / 2 ^ 12) or & HE0) & % & _
Hex ((NASC / 2 ^ 6) and & H3F or & H80) & % & _
HEX (NASC and & H3F or & H80)
szret = szret & uch
End if
End if
Next
Toutf8 = szret
End function
'GB to Unicode --- Convert GB encoding text to unicode encoding text
Function CHINESE2UNICODE (STR)
dim I
dim str_one
dim str_unicode
if (ISNULL (STR)) then
exit function
end if
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
chinese2unicode = str_unicode
end function
'Url decoding
Function urldecode (enstr)
DIM DESTR
dim c, i, v
Destr =
for i = 1 to len (ENSTR)
C = MID (ENSTR, I, 1)
if c =% then
v = Eval (& H+MID (ENSTR, I+1,2))
if v <128 THEN
Destr = Destr & CHR (V)
I = i+2
else
if isvalidhex (mid (enstr, i, 3)) then
if isValidhex (MID (ENSTR, I+3, 3)) then
V = Eval (& H+MID (ENSTR, I+1,2)+MID (ENSTR, I+4,2))
Destr = Destr & CHR (V)
I = i+5
else
v = Eval (& H+MID (ENSTR, I+1,2)+CSTR (HEX (ASC (MID (ENSTR, I+3, 1)))))
Destr = Destr & CHR (V)
I = i+3
end if
else
Destr = Destr & C
end if
end if
else
if c =+ then
Destr = Destr &
else
Destr = Destr & C
end if
end if
next
UrlDecode = Destr
end function
'Determine whether it is an effective hexadecimal code
Function Isvalidhex (STR)
dim C
Isvalidhex = TRUE
str = ucase (STR)
if len (str) <> 3 that isValidhex = false: exit function
if left (str, 1) <>% then isvalidhex = false: exit function
C = MID (STR, 2,1)
if not (((((((((((((((((((((((((((((((((((c <(c> = 0) and ((c <= 9)) or ((c> = a) and (c <= z))) then isValidhex = false: exit function
C = MID (STR, 3,1)
if not (((((((((((((((((((((((((((((((((((c <(c> = 0) and ((c <= 9)) or ((c> = a) and (c <= z))) then isValidhex = false: exit function
end function