473,230 Members | 1,490 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,230 software developers and data experts.

replacing text data in a binary file

I am writing a quick program to edit a binary file that contains file paths
(amongst other things). If I look at the files in notepad, they look like:

<gibberish>file//g:\pathtofile1<gibberish>file//g:\pathtofile2<gibberish>
etc.

I want to remove the "g:\" from the file paths. I wrote a console app that
successfully reads the file and writes a duplicate of it, but fails for some
reason to do the "replacing" of the "g:\". The code follows with a note
showing the line that is not working. When I look at the "s" variable in
break mode, I see that VB does not show the entire file contents, even
though when I write "s" to the second file stream, the entire original file
is duplicated. I suppose this is because the file content isn't intended to
be interpreted as a string (its binary after all). It is probably hitting
some unfriendly bytes that it can't interpret for string operations like
Replace. If that's the case, maybe I need to interact with it a character at
a time, although I'm not sure how I would do a replace that way. Any ideas
or code would be greatly appreciated. As you can tell, I don't do much
binary file I/O.

Sub Main()
'read the binary file into a string var
Dim fs As New FileStream("C:\Source\Sample and
Demo\Foobar\EditFpl\Only Fools.fpl", FileMode.Open, FileAccess.Read)
Dim sr As New StreamReader(fs, System.Text.Encoding.UTF8)
Dim s As String = sr.ReadToEnd
sr.Close()
fs.Close()

'remove the hard-coded drive letter specification
s.Replace("file://G:\", "file://") 'THIS LINE DOES NOT WORK

'write a new binary file with my changes
Dim fs2 As New FileStream("C:\Source\Sample and
Demo\Foobar\EditFpl\Only Fools2.fpl", FileMode.CreateNew, FileAccess.Write)
Dim sw As New StreamWriter(fs2, System.Text.Encoding.UTF8)
sw.Write(s)

sw.Close()
fs2.Close()
End Sub
Nov 20 '05 #1
12 5783
Hi Adam,

A simple one because you are not the first one who did that as you do .

s = s.Replace("file://G:\", "file://") 'THIS LINE DOES NOT WORK

or

dim b as String = s.Replace.......

Before you ask why

:-)

I hope this helps?

Cor
Nov 20 '05 #2
* "Adam J. Schaff" <ab****@adelphia.net> scripsit:
'remove the hard-coded drive letter specification
s.Replace("file://G:\", "file://") 'THIS LINE DOES NOT WORK


'Replace' is a "function", so it returns the result:

\\\
s = s.Replace(...)
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
From the mountains in Austria are comming more and more echo's.
'Replace' is a "function", so it returns the result:

\\\
s = s.Replace(...)
///

Nov 20 '05 #4
Adam,
If you are editing a binary file I would recommend opening the file with a
BinaryReader or even just FileStream directly.
Dim sr As New StreamReader(fs, System.Text.Encoding.UTF8)
If you use a StreamReader, you are actually converting the file into Text
(8bit bytes to 16 bit chars) then converting the file back into Binary.

My two concerns with using a StreamReader are:
1. depending on what the binary file actually contains (an exe for example)
removing or adding characters may actually corrupt the file, as the file
contains length & offset fields...
2. Loosing certain bytes, ones that are not translated nicely from arbitrary
bytes back & forth to Unicode. For example using Encoding.ASCII will trash
your file as ASCII is 7 bit, you will loose all the high order bits. I
suspect with UTF8 you will be OK, however it just does not feel right...

Here is a simple program that will copy a file one byte at a time, the trick
is going to be modify it so it looks for "g:\" one byte at a time and skips
those bytes, only if all three are found... Especially if you want to ensure
they are prefaced with "file//".

Dim input As New FileStream("Only Fools.fpl", FileMode.Open)
Dim output As New FileStream("Only Fools2.fpl", FileMode.Create)
Dim value As Integer
value = input.ReadByte()
Do Until value = -1
output.WriteByte(CByte(value))
value = input.ReadByte()
Loop
input.Close()
output.Close()

Hope this helps
Jay

"Adam J. Schaff" <ab****@adelphia.net> wrote in message
news:Ok**************@TK2MSFTNGP11.phx.gbl... I am writing a quick program to edit a binary file that contains file paths (amongst other things). If I look at the files in notepad, they look like:

<gibberish>file//g:\pathtofile1<gibberish>file//g:\pathtofile2<gibberish>
etc.

I want to remove the "g:\" from the file paths. I wrote a console app that
successfully reads the file and writes a duplicate of it, but fails for some reason to do the "replacing" of the "g:\". The code follows with a note
showing the line that is not working. When I look at the "s" variable in
break mode, I see that VB does not show the entire file contents, even
though when I write "s" to the second file stream, the entire original file is duplicated. I suppose this is because the file content isn't intended to be interpreted as a string (its binary after all). It is probably hitting
some unfriendly bytes that it can't interpret for string operations like
Replace. If that's the case, maybe I need to interact with it a character at a time, although I'm not sure how I would do a replace that way. Any ideas
or code would be greatly appreciated. As you can tell, I don't do much
binary file I/O.

Sub Main()
'read the binary file into a string var
Dim fs As New FileStream("C:\Source\Sample and
Demo\Foobar\EditFpl\Only Fools.fpl", FileMode.Open, FileAccess.Read)
Dim sr As New StreamReader(fs, System.Text.Encoding.UTF8)
Dim s As String = sr.ReadToEnd
sr.Close()
fs.Close()

'remove the hard-coded drive letter specification
s.Replace("file://G:\", "file://") 'THIS LINE DOES NOT WORK

'write a new binary file with my changes
Dim fs2 As New FileStream("C:\Source\Sample and
Demo\Foobar\EditFpl\Only Fools2.fpl", FileMode.CreateNew, FileAccess.Write) Dim sw As New StreamWriter(fs2, System.Text.Encoding.UTF8)
sw.Write(s)

sw.Close()
fs2.Close()
End Sub

Nov 20 '05 #5
Doh! I was so absorbed with the dangers of dealing with binary data as text,
that I forgot to check for obvoius blunders. I've used Replace before and
should have known better! Thanks for not adding "what a flaming idiot" to
your replies. ;-)

"Adam J. Schaff" <ab****@adelphia.net> wrote in message
news:Ok**************@TK2MSFTNGP11.phx.gbl...
I am writing a quick program to edit a binary file that contains file paths (amongst other things). If I look at the files in notepad, they look like:

<gibberish>file//g:\pathtofile1<gibberish>file//g:\pathtofile2<gibberish>
etc.

I want to remove the "g:\" from the file paths. I wrote a console app that
successfully reads the file and writes a duplicate of it, but fails for some reason to do the "replacing" of the "g:\". The code follows with a note
showing the line that is not working. When I look at the "s" variable in
break mode, I see that VB does not show the entire file contents, even
though when I write "s" to the second file stream, the entire original file is duplicated. I suppose this is because the file content isn't intended to be interpreted as a string (its binary after all). It is probably hitting
some unfriendly bytes that it can't interpret for string operations like
Replace. If that's the case, maybe I need to interact with it a character at a time, although I'm not sure how I would do a replace that way. Any ideas
or code would be greatly appreciated. As you can tell, I don't do much
binary file I/O.

Sub Main()
'read the binary file into a string var
Dim fs As New FileStream("C:\Source\Sample and
Demo\Foobar\EditFpl\Only Fools.fpl", FileMode.Open, FileAccess.Read)
Dim sr As New StreamReader(fs, System.Text.Encoding.UTF8)
Dim s As String = sr.ReadToEnd
sr.Close()
fs.Close()

'remove the hard-coded drive letter specification
s.Replace("file://G:\", "file://") 'THIS LINE DOES NOT WORK

'write a new binary file with my changes
Dim fs2 As New FileStream("C:\Source\Sample and
Demo\Foobar\EditFpl\Only Fools2.fpl", FileMode.CreateNew, FileAccess.Write) Dim sw As New StreamWriter(fs2, System.Text.Encoding.UTF8)
sw.Write(s)

sw.Close()
fs2.Close()
End Sub

Nov 20 '05 #6
Jay,

Thanks for the code. I looked at using the binary reader, but couldn't
figure out how to tell when it reaches EOF. Had no idea about the -1 trick.
That said, I'm still not sure what the code would look like to test one byte
at a time for a sequence of 6 characters, particularly if those characters
are stored as 2 bytes each. Hmm, I suppose there is a ReadChar method, but
if I use that instead, I couldn't use the -1 trick. Also, how would I write
it back to the output file if I use ReadChar instead of ReadByte? Is there a
WriteChar, and will it cause problems if some of the data I'm reading with
ReadChar isn't really a char? Ack! I'm just too new to all this. I don't
even understand the use of cbyte in your code (isn't it a byte already?).
Well, at least I have food for thought. Thanks again for the advice. I can
see I have a lot to learn.

Even if I do stay with the stream reader, I'll take your worries to heart
and will add code to backup the file before I play with it. That's just good
common sense.
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uA**************@TK2MSFTNGP12.phx.gbl...
Adam,
If you are editing a binary file I would recommend opening the file with a
BinaryReader or even just FileStream directly.
Dim sr As New StreamReader(fs, System.Text.Encoding.UTF8)
If you use a StreamReader, you are actually converting the file into Text
(8bit bytes to 16 bit chars) then converting the file back into Binary.

My two concerns with using a StreamReader are:
1. depending on what the binary file actually contains (an exe for

example) removing or adding characters may actually corrupt the file, as the file
contains length & offset fields...
2. Loosing certain bytes, ones that are not translated nicely from arbitrary bytes back & forth to Unicode. For example using Encoding.ASCII will trash
your file as ASCII is 7 bit, you will loose all the high order bits. I
suspect with UTF8 you will be OK, however it just does not feel right...

Here is a simple program that will copy a file one byte at a time, the trick is going to be modify it so it looks for "g:\" one byte at a time and skips those bytes, only if all three are found... Especially if you want to ensure they are prefaced with "file//".

Dim input As New FileStream("Only Fools.fpl", FileMode.Open)
Dim output As New FileStream("Only Fools2.fpl", FileMode.Create)
Dim value As Integer
value = input.ReadByte()
Do Until value = -1
output.WriteByte(CByte(value))
value = input.ReadByte()
Loop
input.Close()
output.Close()

Hope this helps
Jay

"Adam J. Schaff" <ab****@adelphia.net> wrote in message
news:Ok**************@TK2MSFTNGP11.phx.gbl...
I am writing a quick program to edit a binary file that contains file paths
(amongst other things). If I look at the files in notepad, they look like:
<gibberish>file//g:\pathtofile1<gibberish>file//g:\pathtofile2<gibberish> etc.

I want to remove the "g:\" from the file paths. I wrote a console app that successfully reads the file and writes a duplicate of it, but fails for

some
reason to do the "replacing" of the "g:\". The code follows with a note
showing the line that is not working. When I look at the "s" variable in
break mode, I see that VB does not show the entire file contents, even
though when I write "s" to the second file stream, the entire original

file
is duplicated. I suppose this is because the file content isn't intended

to
be interpreted as a string (its binary after all). It is probably hitting some unfriendly bytes that it can't interpret for string operations like
Replace. If that's the case, maybe I need to interact with it a character at
a time, although I'm not sure how I would do a replace that way. Any

ideas or code would be greatly appreciated. As you can tell, I don't do much
binary file I/O.

Sub Main()
'read the binary file into a string var
Dim fs As New FileStream("C:\Source\Sample and
Demo\Foobar\EditFpl\Only Fools.fpl", FileMode.Open, FileAccess.Read)
Dim sr As New StreamReader(fs, System.Text.Encoding.UTF8)
Dim s As String = sr.ReadToEnd
sr.Close()
fs.Close()

'remove the hard-coded drive letter specification
s.Replace("file://G:\", "file://") 'THIS LINE DOES NOT WORK

'write a new binary file with my changes
Dim fs2 As New FileStream("C:\Source\Sample and
Demo\Foobar\EditFpl\Only Fools2.fpl", FileMode.CreateNew,

FileAccess.Write)
Dim sw As New StreamWriter(fs2, System.Text.Encoding.UTF8)
sw.Write(s)

sw.Close()
fs2.Close()
End Sub


Nov 20 '05 #7
p.s. I just notice that value is an integer. That explains the cbyte in your
code, but now I'm confused why ReadByte returns an integer?? Is it something
to do with testing for EOF? (-1 isn't a typical byte value it occurs to me
;)

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uA**************@TK2MSFTNGP12.phx.gbl...
Adam,
If you are editing a binary file I would recommend opening the file with a
BinaryReader or even just FileStream directly.
Dim sr As New StreamReader(fs, System.Text.Encoding.UTF8)
If you use a StreamReader, you are actually converting the file into Text
(8bit bytes to 16 bit chars) then converting the file back into Binary.

My two concerns with using a StreamReader are:
1. depending on what the binary file actually contains (an exe for

example) removing or adding characters may actually corrupt the file, as the file
contains length & offset fields...
2. Loosing certain bytes, ones that are not translated nicely from arbitrary bytes back & forth to Unicode. For example using Encoding.ASCII will trash
your file as ASCII is 7 bit, you will loose all the high order bits. I
suspect with UTF8 you will be OK, however it just does not feel right...

Here is a simple program that will copy a file one byte at a time, the trick is going to be modify it so it looks for "g:\" one byte at a time and skips those bytes, only if all three are found... Especially if you want to ensure they are prefaced with "file//".

Dim input As New FileStream("Only Fools.fpl", FileMode.Open)
Dim output As New FileStream("Only Fools2.fpl", FileMode.Create)
Dim value As Integer
value = input.ReadByte()
Do Until value = -1
output.WriteByte(CByte(value))
value = input.ReadByte()
Loop
input.Close()
output.Close()

Hope this helps
Jay

"Adam J. Schaff" <ab****@adelphia.net> wrote in message
news:Ok**************@TK2MSFTNGP11.phx.gbl...
I am writing a quick program to edit a binary file that contains file paths
(amongst other things). If I look at the files in notepad, they look like:
<gibberish>file//g:\pathtofile1<gibberish>file//g:\pathtofile2<gibberish> etc.

I want to remove the "g:\" from the file paths. I wrote a console app that successfully reads the file and writes a duplicate of it, but fails for

some
reason to do the "replacing" of the "g:\". The code follows with a note
showing the line that is not working. When I look at the "s" variable in
break mode, I see that VB does not show the entire file contents, even
though when I write "s" to the second file stream, the entire original

file
is duplicated. I suppose this is because the file content isn't intended

to
be interpreted as a string (its binary after all). It is probably hitting some unfriendly bytes that it can't interpret for string operations like
Replace. If that's the case, maybe I need to interact with it a character at
a time, although I'm not sure how I would do a replace that way. Any

ideas or code would be greatly appreciated. As you can tell, I don't do much
binary file I/O.

Sub Main()
'read the binary file into a string var
Dim fs As New FileStream("C:\Source\Sample and
Demo\Foobar\EditFpl\Only Fools.fpl", FileMode.Open, FileAccess.Read)
Dim sr As New StreamReader(fs, System.Text.Encoding.UTF8)
Dim s As String = sr.ReadToEnd
sr.Close()
fs.Close()

'remove the hard-coded drive letter specification
s.Replace("file://G:\", "file://") 'THIS LINE DOES NOT WORK

'write a new binary file with my changes
Dim fs2 As New FileStream("C:\Source\Sample and
Demo\Foobar\EditFpl\Only Fools2.fpl", FileMode.CreateNew,

FileAccess.Write)
Dim sw As New StreamWriter(fs2, System.Text.Encoding.UTF8)
sw.Write(s)

sw.Close()
fs2.Close()
End Sub


Nov 20 '05 #8
Adam,
&hFF (-1) is a valid Byte value, returning an integer allows -1 for EOF &
&HFF for the byte.

Hope this helps
Jay

"Adam J. Schaff" <as*****@cascocdev.com> wrote in message
news:OU**************@tk2msftngp13.phx.gbl...
p.s. I just notice that value is an integer. That explains the cbyte in your code, but now I'm confused why ReadByte returns an integer?? Is it something to do with testing for EOF? (-1 isn't a typical byte value it occurs to me
;)

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uA**************@TK2MSFTNGP12.phx.gbl...
Adam,
If you are editing a binary file I would recommend opening the file with a
BinaryReader or even just FileStream directly.
Dim sr As New StreamReader(fs, System.Text.Encoding.UTF8)


If you use a StreamReader, you are actually converting the file into Text (8bit bytes to 16 bit chars) then converting the file back into Binary.

My two concerns with using a StreamReader are:
1. depending on what the binary file actually contains (an exe for

example)
removing or adding characters may actually corrupt the file, as the file
contains length & offset fields...
2. Loosing certain bytes, ones that are not translated nicely from

arbitrary
bytes back & forth to Unicode. For example using Encoding.ASCII will trash your file as ASCII is 7 bit, you will loose all the high order bits. I
suspect with UTF8 you will be OK, however it just does not feel right...

Here is a simple program that will copy a file one byte at a time, the

trick
is going to be modify it so it looks for "g:\" one byte at a time and

skips
those bytes, only if all three are found... Especially if you want to

ensure
they are prefaced with "file//".

Dim input As New FileStream("Only Fools.fpl", FileMode.Open)
Dim output As New FileStream("Only Fools2.fpl", FileMode.Create)
Dim value As Integer
value = input.ReadByte()
Do Until value = -1
output.WriteByte(CByte(value))
value = input.ReadByte()
Loop
input.Close()
output.Close()

Hope this helps
Jay

"Adam J. Schaff" <ab****@adelphia.net> wrote in message
news:Ok**************@TK2MSFTNGP11.phx.gbl...
I am writing a quick program to edit a binary file that contains file

paths
(amongst other things). If I look at the files in notepad, they look like:
<gibberish>file//g:\pathtofile1<gibberish>file//g:\pathtofile2<gibberish> etc.

I want to remove the "g:\" from the file paths. I wrote a console app that successfully reads the file and writes a duplicate of it, but fails for some
reason to do the "replacing" of the "g:\". The code follows with a
note showing the line that is not working. When I look at the "s" variable in break mode, I see that VB does not show the entire file contents, even
though when I write "s" to the second file stream, the entire original

file
is duplicated. I suppose this is because the file content isn't intended
to
be interpreted as a string (its binary after all). It is probably

hitting some unfriendly bytes that it can't interpret for string operations
like Replace. If that's the case, maybe I need to interact with it a

character
at
a time, although I'm not sure how I would do a replace that way. Any

ideas or code would be greatly appreciated. As you can tell, I don't do much
binary file I/O.

Sub Main()
'read the binary file into a string var
Dim fs As New FileStream("C:\Source\Sample and
Demo\Foobar\EditFpl\Only Fools.fpl", FileMode.Open, FileAccess.Read)
Dim sr As New StreamReader(fs, System.Text.Encoding.UTF8)
Dim s As String = sr.ReadToEnd
sr.Close()
fs.Close()

'remove the hard-coded drive letter specification
s.Replace("file://G:\", "file://") 'THIS LINE DOES NOT WORK

'write a new binary file with my changes
Dim fs2 As New FileStream("C:\Source\Sample and
Demo\Foobar\EditFpl\Only Fools2.fpl", FileMode.CreateNew,

FileAccess.Write)
Dim sw As New StreamWriter(fs2, System.Text.Encoding.UTF8)
sw.Write(s)

sw.Close()
fs2.Close()
End Sub



Nov 20 '05 #9
Adam,
For a binary file, it really depends on the encoding, which I would try to
avoid! If you were using UTF8 and it worked then there is 1 char per byte.
If you need UTF16, then you have (16bit) Unicode itself & there are 2 bytes
per char (in the file), there is also a UTF32 ;-). In other words do not
confuse how a string is represented in memory and how text is encoded in a
file. Binary files could actually have multiple encodings of text. Consider
a file that stores the code page & the length of a string, followed by the
code page encoded value of the string... Speaking of which if you binary
file stores the length of the string, removing the "g:\" may cause problems
;-)

If you start using ReadChar & WriteChar you are back to translating to Text.

Assuming your file is not EBCDIC & you are not using any extended character
(an umlated a for example ""). A single byte in your file will contain a
single character. EBCDIC you still have 1 byte per single character however
its bit representation are different, extended characters (ANSI code pages)
are single character per byte, but bytes 128 to 255 have different bit
representations...

You can then use Asc or AscW to convert a char into a integer/byte.
value = input.ReadByte()
Do Until value = -1 if value = AscW("G"c)
' found a G, look for a :
End if
output.WriteByte(CByte(value))
value = input.ReadByte()
Loop
For information on Unicode and other character sets see:

http://www.yoda.arachsys.com/csharp/unicode.html

A couple other articles that may help:
http://www.yoda.arachsys.com/csharp/...ngunicode.html

Hope this helps
Jay

"Adam J. Schaff" <as*****@cascocdev.com> wrote in message
news:ev**************@TK2MSFTNGP12.phx.gbl...
Jay,

Thanks for the code. I looked at using the binary reader, but couldn't
figure out how to tell when it reaches EOF. Had no idea about the -1 trick. That said, I'm still not sure what the code would look like to test one byte at a time for a sequence of 6 characters, particularly if those characters
are stored as 2 bytes each. Hmm, I suppose there is a ReadChar method, but
if I use that instead, I couldn't use the -1 trick. Also, how would I write it back to the output file if I use ReadChar instead of ReadByte? Is there a WriteChar, and will it cause problems if some of the data I'm reading with
ReadChar isn't really a char? Ack! I'm just too new to all this. I don't
even understand the use of cbyte in your code (isn't it a byte already?).
Well, at least I have food for thought. Thanks again for the advice. I can
see I have a lot to learn.

Even if I do stay with the stream reader, I'll take your worries to heart
and will add code to backup the file before I play with it. That's just good common sense.
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uA**************@TK2MSFTNGP12.phx.gbl...
Adam,
If you are editing a binary file I would recommend opening the file with

a BinaryReader or even just FileStream directly.
Dim sr As New StreamReader(fs, System.Text.Encoding.UTF8)


If you use a StreamReader, you are actually converting the file into Text (8bit bytes to 16 bit chars) then converting the file back into Binary.

My two concerns with using a StreamReader are:
1. depending on what the binary file actually contains (an exe for

example)
removing or adding characters may actually corrupt the file, as the file
contains length & offset fields...
2. Loosing certain bytes, ones that are not translated nicely from

arbitrary
bytes back & forth to Unicode. For example using Encoding.ASCII will trash your file as ASCII is 7 bit, you will loose all the high order bits. I
suspect with UTF8 you will be OK, however it just does not feel right...

Here is a simple program that will copy a file one byte at a time, the

trick
is going to be modify it so it looks for "g:\" one byte at a time and

skips
those bytes, only if all three are found... Especially if you want to

ensure
they are prefaced with "file//".

Dim input As New FileStream("Only Fools.fpl", FileMode.Open)
Dim output As New FileStream("Only Fools2.fpl", FileMode.Create)
Dim value As Integer
value = input.ReadByte()
Do Until value = -1
output.WriteByte(CByte(value))
value = input.ReadByte()
Loop
input.Close()
output.Close()

Hope this helps
Jay

"Adam J. Schaff" <ab****@adelphia.net> wrote in message
news:Ok**************@TK2MSFTNGP11.phx.gbl...
I am writing a quick program to edit a binary file that contains file

paths
(amongst other things). If I look at the files in notepad, they look like:
<gibberish>file//g:\pathtofile1<gibberish>file//g:\pathtofile2<gibberish> etc.

I want to remove the "g:\" from the file paths. I wrote a console app that successfully reads the file and writes a duplicate of it, but fails for some
reason to do the "replacing" of the "g:\". The code follows with a
note showing the line that is not working. When I look at the "s" variable in break mode, I see that VB does not show the entire file contents, even
though when I write "s" to the second file stream, the entire original

file
is duplicated. I suppose this is because the file content isn't intended
to
be interpreted as a string (its binary after all). It is probably

hitting some unfriendly bytes that it can't interpret for string operations
like Replace. If that's the case, maybe I need to interact with it a

character
at
a time, although I'm not sure how I would do a replace that way. Any

ideas or code would be greatly appreciated. As you can tell, I don't do much
binary file I/O.

Sub Main()
'read the binary file into a string var
Dim fs As New FileStream("C:\Source\Sample and
Demo\Foobar\EditFpl\Only Fools.fpl", FileMode.Open, FileAccess.Read)
Dim sr As New StreamReader(fs, System.Text.Encoding.UTF8)
Dim s As String = sr.ReadToEnd
sr.Close()
fs.Close()

'remove the hard-coded drive letter specification
s.Replace("file://G:\", "file://") 'THIS LINE DOES NOT WORK

'write a new binary file with my changes
Dim fs2 As New FileStream("C:\Source\Sample and
Demo\Foobar\EditFpl\Only Fools2.fpl", FileMode.CreateNew,

FileAccess.Write)
Dim sw As New StreamWriter(fs2, System.Text.Encoding.UTF8)
sw.Write(s)

sw.Close()
fs2.Close()
End Sub



Nov 20 '05 #10
Thanks for the sample code and links! I realize that removing characters
might be a problem. If that happens, I might try substituting the new drive
letter (e.g. "H:\") for the old and just running this on the file every time
the drive letter changes. Not my first choice, but I bet that would work
because it won't change the file length. Thanks again for all your help.
Nov 20 '05 #11
* "Cor Ligthert" <no**********@planet.nl> scripsit:
From the mountains in Austria are comming more and more echo's.
'Replace' is a "function", so it returns the result:

\\\
s = s.Replace(...)
///


.... and I am living in Austria, so I don't hear them.

:-)))

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #12
Adam,
One other concern I had was if the file has any check sums in it, to
"prevent" people from tampering with it...

Change G:\ to H:\ will change the check sum...

Just a thought
Jay

"Adam J. Schaff" <as*****@cascocdev.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Thanks for the sample code and links! I realize that removing characters
might be a problem. If that happens, I might try substituting the new drive letter (e.g. "H:\") for the old and just running this on the file every time the drive letter changes. Not my first choice, but I bet that would work
because it won't change the file length. Thanks again for all your help.

Nov 20 '05 #13

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

Similar topics

13
by: yaipa | last post by:
What would be the common sense way of finding a binary pattern in a ..bin file, say some 200 bytes, and replacing it with an updated pattern of the same length at the same offset? Also, the...
27
by: Eric | last post by:
Assume that disk space is not an issue (the files will be small < 5k in general for the purpose of storing preferences) Assume that transportation to another OS may never occur. Are there...
8
by: Yeow | last post by:
hello, i was trying to use the fread function on SunOS and ran into some trouble. i made a simple test as follows: i'm trying to read in a binary file (generated from a fortran code) that...
50
by: Michael Mair | last post by:
Cheerio, I would appreciate opinions on the following: Given the task to read a _complete_ text file into a string: What is the "best" way to do it? Handling the buffer is not the problem...
36
by: Wei Su | last post by:
Hi, I have a text file abc.txt and it looks like: 12 34 56 23 45 56 33 56 78 ... .. .. ... .. .. I want to get how many rows totally in the text file, how to do this? Thanks.
7
by: Ryan Liu | last post by:
Hi, I want to backup database to a text file. There are binary columns. I read byte from the column and use ASCII encoding convert it to string and write to a text file. But there are bytes...
14
by: Josh Baltzell | last post by:
I am having a lot more trouble with this than I thought I would. Here is what I want to do in pseudocode. Open c:\some.pdf Replace "Replace this" with "Replaced!" Save c:\some_edited.pdf I...
3
by: Lauren Quantrell | last post by:
I have an HTML file named myHTML.htm It looks like this: <great HTML code> <more great HTML code> <even more great HTML code> <insert HTML here>
5
by: dm3281 | last post by:
Hello, I have a text report from a mainframe that I need to parse. The report has about a 2580 byte header that contains binary information (garbage for the most part); although there are a...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...

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.