<%
'==================================================
' Function name: Gb2big5
' Function: GB code turns big five yards
' Argument: Text------string
' Author: netyum (Yang Song)
' Q q:8025628
' Time: June 28, 2004
'==================================================
Function Gb2big5 (Text)
Dim ados,max,i,c,b,h,l
If IsNull (text) Or Text = "" Then Exit Function
Set ados=server.createobject ("ADODB.stream")
Ados.mode = 3
Ados.type = 1
Ados.open
Ados.loadfromfile (Server.MapPath ("gb-big5.table"))
Text = Server.URLEncode (text)
b = ""
Max = Len (Text)
For I=1 to Max
c = Mid (text,i,1)
If C = "%" Then
H = eval ("&h" +mid (text,i+1,2))
If H < 128 Then
b = B & Chr (h)
i = i+2
Else
If Isvalidhex (Mid (text,i,3)) Then
If Isvalidhex (Mid (text,i+3,3)) Then
L = eval ("&h" +mid (text,i+4,2))
Ados.position = (h-160) *510+ (L-1) *2
B = B & Bytes2bstr (Ados.read (2))
i = i+5
Else
B = B & ""
i = i+3
End If
End If
End If
Else
If C = "+" Then
B = B & ""
Else
B = B & C
End If
End If
Next
Set ADOs = Nothing
Gb2big5 = b
End Function
Function Isvalidhex (str)
Isvalidhex=true
Str=ucase (str)
If Len (str) <> 3 Then isvalidhex = False:exit Function
If left (str,1) <> "%" Then Isvalidhex = False:exit Function
c = Mid (str,2,1)
If Not ((c>= "0") and (c<= "9")) Or ((c>= "A") and (c<= "Z")) Then Isvalidhex = False:exit Function
c = Mid (str,3,1)
If Not ((c>= "0") and (c<= "9")) Or ((c>= "A") and (c<= "Z")) Then Isvalidhex = False:exit Function
End Function
Function Bytes2bstr (vIn)
Dim Strreturn
Dim I,thischarcode,nextcharcode
Strreturn = ""
For i = 1 to LenB (vIn)
Thischarcode = AscB (MidB (vin,i,1))
If Thischarcode < &h80 Then
Strreturn = Strreturn & Chr (Thischarcode)
Else
Nextcharcode = AscB (MidB (vin,i+1,1))
Strreturn = Strreturn & Chr (CLng (thischarcode) * &h100 + CInt (nextcharcode))
i = i + 1
End If
Next
Bytes2bstr = Strreturn
End Function
%>