ASP GB turn big five yards

Source: Internet
Author: User
Tags exit chr eval
<%
'==================================================
' 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
%>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.