Streamwriting a large ASCII string to a file

M

Mike Cooper

Hi everyone,

I am using vb.net to edit the ascii code of a print stream directly.
Why am I doing this? It's complicated but its something my boss
needs. I am successfully using Streamreader to read all of the data
into a string:

Dim FixFile_StreamReader as StreamReader
FixFile_StreamReader = File.OpenText(MyOldFile)
FileString = FixFile_StreamReader.ReadToEnd
FixFile_StreamReader.Close()

This produces a string ("FileString") which is 237839 bytes long. I
am making my changes to this string and then attempting to write this
string back into a new file. This is where I am having problems. The
new file is exactly the same size as the old, but the data in it is
convoluted; a few similarlities, but mostly trash.

The Streamwriter is set up for ascii encoding. Beyond that I have no
idea what else to try. Can anyone help?

thank you,
Mike Cooper
 
A

Armin Zingler

Mike Cooper said:
Hi everyone,

I am using vb.net to edit the ascii code of a print stream directly.
Why am I doing this? It's complicated but its something my boss
needs. I am successfully using Streamreader to read all of the
data into a string:

Dim FixFile_StreamReader as StreamReader
FixFile_StreamReader = File.OpenText(MyOldFile)
FileString = FixFile_StreamReader.ReadToEnd
FixFile_StreamReader.Close()

This produces a string ("FileString") which is 237839 bytes long.
I am making my changes to this string and then attempting to write
this string back into a new file. This is where I am having
problems. The new file is exactly the same size as the old, but the
data in it is convoluted; a few similarlities, but mostly trash.

The Streamwriter is set up for ascii encoding. Beyond that I have
no idea what else to try. Can anyone help?

You know that the code above expects an UTF-8 encoded file and that ascii =
7 bits only?


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
M

Mike Cooper

Ummm....no, I didn't. But using UTF-8 encoding on the streamwriter,
didn't make a difference. The resulting garbage was different but it
was still garbage. Same for UNICODE too!
 
A

Armin Zingler

Mike Cooper said:
Ummm....no, I didn't. But using UTF-8 encoding on the
streamwriter, didn't make a difference. The resulting garbage was
different but it was still garbage. Same for UNICODE too!

What is the encoding of the source file? Is it really UTF-8? Is it a text
file at all?

If it's not UTF-8, use an io.filestream and an io.streamreader instead where
you can specify the source enconding explicitly.

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 

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