×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

asp help: hex to string. I have a function to convert string to hex; but how can i do the opposite way. To convert hex back to string? thx.

<%
Public Function bu_Str2Hex(str)
' Converts string <str> of chars to string in hex byte format
' E.g. "abc" will be converted to "616263"
sHex = ""

n = Len(str)
For i = 1 To n
byt = CByte(Asc(Mid(str, i, 1)))
If Len(Hex(byt)) = 1 Then
sHex = sHex & "0" & Hex(byt)
Else
sHex = sHex & Hex(byt)
End If
Next
bu_Str2Hex = sHex

End Function


Str = "abc"
strHex = bu_Str2Hex(str)
%>

<html>
str: [<%= Str %>]<br>
hex: [<%= strHex %>]

</html>
Report

Replies, comments and Discussions:

  • 工作学习 / 专业技术讨论 / asp help: hex to string. I have a function to convert string to hex; but how can i do the opposite way. To convert hex back to string? thx.
    <%
    Public Function bu_Str2Hex(str)
    ' Converts string <str> of chars to string in hex byte format
    ' E.g. "abc" will be converted to "616263"
    sHex = ""

    n = Len(str)
    For i = 1 To n
    byt = CByte(Asc(Mid(str, i, 1)))
    If Len(Hex(byt)) = 1 Then
    sHex = sHex & "0" & Hex(byt)
    Else
    sHex = sHex & Hex(byt)
    End If
    Next
    bu_Str2Hex = sHex

    End Function


    Str = "abc"
    strHex = bu_Str2Hex(str)
    %>

    <html>
    str: [<%= Str %>]<br>
    hex: [<%= strHex %>]

    </html>
    • use Chr()
      • i have found the soluction. thx