Replace Bytes

G

Guest

dim br as BinaryReader(stream)
dim buf(5000) as byte
br.Read(buf,0,5000)
closeit..
I have read a binary file into a buffer. This buffer contains many different
chars as well as a few null chars. I want to replace the (NULLS)chr(0)'s
with (SPACES)chr(32)'s. How can I do this. REPLACE does not seem to be an
option, If I converted it to a string I was afraid the string would stop at
the first NULL truncating the remaining chars. Any ideas on how to do
this...
Thanks
JT
 
G

Guest

All you have to do is iterate over the byte array and replace the occurances
of 0 with 32. No need to convert it to a string.

But, you might want to keep track of exactly how many bytes you read from
the file and only iterate over that many in the array.

For i As Integer = 0 to buf.Length - 1
If buf(i) = 0 Then
buf(i) = 32
End If
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top