# asp國標轉大五碼

<%
'==================================================
'函數名：gb2big5
'作 用：國標碼轉大五碼
'參 數：Text ------ 字串
'作 者：netyum(楊嵩)
'Q Q: 8025628
'時 間：2004年6月28日
'==================================================
Function gb2big5(Text)
If IsNull(Text) Or Text = "" Then Exit Function

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))
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
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
%>

## E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

## Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

## Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth \$300-1200 USD