about 5 years ago

使用Chrome瀏覽器時發現,若網址列有中文,chrome不會自動執行
所以我作了一隻測試程式,去滿足各個條件
後來得出結果,其實只需要使用Server.URLEcode("中文")就可以解決這個問題
Sample Code如下

<%
    a = "中文字" 
    b = Server.URLEncode(Convert_ASCII_Unicode(a))
    c = Server.URLEncode(Convert_Unicode_ASCII(a))
    Response.write "a:" & Server.URLEncode(a) & "</br>"
    Response.write "b:" & b & "</br>"
    Response.write "c:" & c & "</br>"
    Response.Write "d:" & Request("D") & "</br>"
    Response.Write "e:" & Request("E") & "</br>"
    Response.end()
    


Function Convert_ASCII_Unicode(str)
    Dim old,new_w,j
    old = str
    new_w = ""
    For j = 1 To Len(str)
        if ascw(mid(old,j,1)) < 0 then
            new_w = new_w & "&#" & ascw(mid(old,j,1)) + 65536 & ";"
        ElseIf ascw(mid(old,j,1))>0 and ascw(mid(old,j,1))<127 then
            new_w = new_w & mid(old,j,1)
        Else
            new_w = new_w & "&#" & ascw(mid(old,j,1)) & ";"
        End if
    Next
    Convert_ASCII_Unicode = new_w
End Function


Function Convert_Unicode_ASCII(str) 
    Dim x,y,z,temp_word,flag
    flag = 0
    x = InStr(flag + 1,str,"&#")
    Do Until x = 0 or x < flag
        x = InStr(flag + 1,str,"&#")
        if x <> 0 then
            y = Mid(str,x,8)
            Select Case InStr(y,";")
                Case 8
                    z = chrw(Mid(y,3,5))
                Case 7
                    z = chrw(Mid(y,3,4))
                Case 6
                    z = chrw(Mid(y,3,3))
                Case 5
                    z = chrw(Mid(y,3,2))
            End Select

            if InStr(y,";") > 4 And Asc(z) <> 63 then
                str = Replace(str,Left(y,InStr(y,";")),z)
            End if
             flag = x
         End if
    Loop
    Convert_Unicode_ASCII = str
End Function
%>

← C# 繁簡轉換工具 獅子,狼,與綿羊的管理哲學 →
 
comments powered by Disqus