ByteArrayToHexString.vbs
'====' How to create a true Byte Array in VBScript.
' A true Byte Array will have Typename() -> "Byte()"
'====
Const adTypeBinary = 1
Const adTypeText = 2
Const adSaveCreateOverWrite = 2
set fso = createobject("scripting.filesystemobject")
set stream = createobject("adodb.stream")
temp = fso.gettempname()
stream.type = adTypeText
stream.charset = "ASCII"
stream.open
'here you would loop over your binary source string
'with lenb(),midb(),ascb(),chrb() functions...
'
'this demo loop from 0 to 255 just proves that
'stream.writetext is OK with any binary character value...
'
for i = 0 to 255
wscript.echo i,chr(i)
stream.writetext chr(i)
next
stream.savetofile temp, adSaveCreateOverWrite
stream.close
stream.type = adTypeBinary
stream.open
stream.loadfromfile temp
trueByteArray = stream.read
stream.close
fso.deletefile temp
msgbox "typename(trueByteArray) -> " & typename(trueByteArray)
msgbox ByteArrayToHexString(trueByteArray)
wscript.quit
Function ByteArrayToHexString(bytearray)
Dim I
Redim B(lenb(bytearray)-1)
For I=1 to lenb(bytearray)
B(I-1) = right("0" & hex(AscB(MidB(bytearray,I,1))),2)
Next
ByteArrayToHexString = Join(B,",")
End Function
页:
[1]