Vbscript 在二进制流中搜索和替换

Vbscript 在二进制流中搜索和替换,vbscript,binarystream,Vbscript,Binarystream,我正在尝试更改ByTestStream数组中的值。我正在寻找空值,我想把它改成一个空格。当我尝试访问阵列时,会收到一条错误消息“类型不匹配” 我的VBS代码: Const adTypeBinary = 1 Const adSaveCreateOverWrite = 2 Const adSaveCreateNotExist=1 'Create Stream object Dim BinaryStream Set BinaryStream = CreateObject("ADODB.Stream")

我正在尝试更改ByTestStream数组中的值。我正在寻找空值,我想把它改成一个空格。当我尝试访问阵列时,会收到一条错误消息“类型不匹配”

我的VBS代码:

Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Const adSaveCreateNotExist=1
'Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
Dim InputFile
InputFile="C:\Users\oferbe\Documents\Tfachut\prepr\Testinput.txt"

'Specify stream type - we want To get binary data.
BinaryStream.Type = adTypeBinary

'Open the stream
BinaryStream.Open
'Load the file data from disk To stream object
BinaryStream.LoadFromFile InputFile

'Open the stream And get binary data from the object
ReadBinaryFile = BinaryStream.Read
BinaryStream.Close

For i = 0 to UBound(ReadBinaryFile)
  If ReadBinaryFile(i)=00 Then ReadBinaryFile(i)=20
Next

BinaryStream.Open
'BinaryStream.Write ByteArray
BinaryStream.Write ReadBinaryFile
Dim OutPutFile
OutPutFile="C:\Users\oferbe\Documents\Tfachut\prepr\Ofer"
'Save binary data To disk
BinaryStream.SaveToFile OutPutFile, adSaveCreateOverWrite

Read
操作返回一个字节数组,它基本上是一个二进制字符串,具有VBScript数组的一些属性,但不是所有属性。最好将二进制流作为常规字符串读取:

inputFile=“C:\path\to\your\input.bin”
outputFile=“C:\path\to\your\output.bin”
Set stream=CreateObject(“ADODB.stream”)
小溪,打开
stream.Type=2
stream.Charset=“Windows-1252”
stream.LoadFromFile输入文件
data=stream.ReadText
关闭
数据=替换(数据,Chr(0),Chr(32))
小溪,打开
stream.Type=2
stream.Charset=“Windows-1252”
stream.WriteText数据
stream.SaveToFile输出文件,2
关闭
设置流=无