StreamWriter/StreamReader

R

rbutch

hey guys, i have a prg that writes a flat text file with specific (spacing) whitespace between the elements.
that works fine.

but i was curious: when i use streamReader to read that back and say put into a listbox, the spacing (formatting) goes away.
does anyone have any insight on how to keep the formatting on this?
here's how im reading it.

Dim sr As New StreamReader("C:\MyFile.text")
Dim line As String
line = ""
Try
While (sr.Peek > -1)
line = sr.ReadLine
lstOne.Items.Add(line)
End While
Finally
sr.Close()
End Try

thanks again
rik


**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
K

Kevin Steffer [MCP]

Hi Rik

Could you post a sample of your text file?
I'm not sure I understand how the formatting goes away!

-Kevin
 
R

rbutch

sure - the formatting is actually in the middle so each readline between the beginning and end.
for instance, in the original .txt file between the 14 and *050610HQJ 777777777
that you see below on two lines is actually on one line with (34) spaces between them.
i guess they wrapped on this web form.

however:
the spaces are critical because they upload to a legacy mainframe that uses placeholders,so depending on the data, there'll either be specific spaces or backfilled
with 0's.
other than the wrapping after the 14, 15 ,10 etc, this is how it appears in the txt file.

ZTCANMA9557 R1023000023400 14 *050610HQJ 777777777
ZTCANMA9557 R1008000023400 15 *050610HQJ 777777777
ZTCANMF5263 R0 050610HQJ 777777777
ZTCANMF5263 R1090000023400 10 *050610HQJ 777777777
ZTCANMF5263 R1000000000000J01500 03 050610HQJ 777777777
T0000020000004

when it loads into the listbox,(taking the first line),all spacing dissappears.


ZTCANMA9557R102300002340014*050610HQJ777777777

hopefully this helps. as i said, it's not crital since the text file is the important thing. i was just reading this back to the user.
thanks again.
rik

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
K

Kevin Steffer [MCP]

Hi again Rik

I tried to copy your text-sample into a txt file and made a simple form
with a listbox control on it. Copy your code from your previous post
and I get alle the spaces in my listbox as they appear in the
text-file.
But I think the issue might be how the text file is written. I copied
the text sample and pasted into notepad.
Se my demo for how I made this work as you'd expect:
http://www.steffer.dk/video/rik_demo.wmv

For writing I have the best compatibility with writing to a text file
created this way:
StreamWriter sw = new
StreamWriter("file.txt",false,System.Text.Encodings.GetEncoding("windows-1252"));
It is C# though, but should be similiar in VB

-Kevin
 

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