紫水晶编程技术论坛 - 努力打造成全国最好的编程论坛

 找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 4781|回复: 0

ByteArrayToHexString.vbs

[复制链接]

96

主题

254

帖子

4

精华

核心会员

Rank: 20Rank: 20Rank: 20Rank: 20

积分
6513
发表于 2012-6-6 07:18:41 | 显示全部楼层 |阅读模式
'====
' 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
您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

手机版|Archiver|紫水晶工作室 ( 粤ICP备05020336号 )

GMT+8, 2024-4-29 23:30 , Processed in 0.022543 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表