日期:2014-05-17  浏览次数:20706 次

将ASCII16进制转成字符串?有这样的函数吗?
我用下面这个函数将字符串转成了ASCII16进制,但是无法转回来。

function strToAsc(strValue) 
dim strTemp,c,m
dim i 
strTemp="" 
for i=1 to len(strValue & "") 
c = asc(mid(strValue,i,1))
if c>=0 and c<256 then m="" else m=""
strTemp=strTemp &m& hex(c)
next 
strToAsc=strTemp 
end function


123 得到的是 313233 这个是对的。

但是313233 如何转成 123呢?

------解决方案--------------------

VBScript code

Response.Write toStr("313233")

Function toStr(s)
    Dim t, i, c, r
    r = ""
    For i = 1 To Len(s) Step 2
        t = Mid(s, i, 2)
        c = CInt("&" & "H" & t)
        If c > 127 Then
            t = Mid(s, i, 4)
            c = CInt("&" & "H" & t)
            i = i + 2
        End If
        r = r & Chr(c)
    Next
    toStr = r
End Function