VBS如何把字符串转换为16进制数值?

例如:把字符串"100ABC"转换为16进制数值,然后可以加1变为100ABD,加4自动进位变为100AC0
注:是VBS不是vb

Public Function StrToHex(ByVal strS As String) As String
'将字符串转换为16进制
Dim abytS() As Byte
Dim bytTemp As Byte
Dim strTemp As String
Dim lLocation As Long
abytS = StrConv(strS, vbFromUnicode)
For lLocation = 0 To UBound(abytS)
bytTemp = abytS(lLocation)
strTemp = Hex(bytTemp)
strTemp = Right("00" & strTemp, 2)
StrToHex = StrToHex & strTemp
Next lLocation
StrToHex = StrToHex
End Function

Public Function HexToStr(str As String) As String
'将16进制转换为字符串
Dim rst() As Byte
Dim i As Long, j As Long, strlong As Long
strlong = Len(str)
ReDim rst(strlong \ 2)
For i = 0 To strlong - 1 Step 2
Dim tmp As Long
rst(i / 2) = Val("&H" & Mid(str, i + 1, 2))
Next
HexToStr = StrConv(rst, vbUnicode)
End Function
温馨提示:答案为网友推荐,仅供参考
相似回答