473,326 Members | 2,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Replace Bytes

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
Apr 12 '07 #1
1 3083
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

--
<i><b>RageInTheMachine9532</b></i><font size="-2">
"<i>...a pungent, ghastly, stinky piece of cheese!</i>" <b>-- The Roaming
Gnome</b></font>
"JT" wrote:
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
Apr 12 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Leif K-Brooks | last post by:
For my web-based application, I need to make twelve different calls to str.replace for the content of /every/ page on /every/ page view (or find a harder to implement and probably less elegant...
4
by: Rich | last post by:
I am trying to replace the word "test" in a file with the word "Change" without creating a new file using the following code: #! /usr/bin/perl -w open (IN, "+</path/to/file/test.html"); ...
6
by: Jon Slaughter | last post by:
I'm trying to replace some bytes in a file using fstream but all I seem to be able to do is append or 0 the file then write... Basicaly I just need to replace the first 512 bytes of the file with...
8
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had...
20
by: hagai26 | last post by:
I am looking for the best and efficient way to replace the first word in a str, like this: "aa to become" -> "/aa/ to become" I know I can use spilt and than join them but I can also use regular...
3
by: RickN | last post by:
What is the best way to open a file and perform a search and replace for multiple char values. Thanks, RickN
3
by: Mullin Yu | last post by:
I have a file, and want to replace some bytes by other bytes e.g. Old: 1b 25 New: 1b 26 66 31 30 30 59 1b 26 66 58 How to implement? Thanks!
5
by: enno | last post by:
Dear Community, We have a problem with null-Bytes in varchar-Columns, which are not handled correctly in our application. Therefor we try to filter them out using the Transact-SQL REPLACE...
3
by: mouac01 | last post by:
Newbie here. How do I do a find and replace in a binary file? I need to read in a binary file then replace a string "ABC" with another string "XYZ" then write to a new file. Find string is the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.