|
-
Nov 1st, 2003, 02:07 PM
#1
Thread Starter
New Member
Line Input
I am having trouble with Streamreader and Stream writer. I don't understand them very well. I am trying to do a simple task:
I want to read an entire file into a text box (which works well using StreaReader (sr.Readto End).
However, all I want to do is take that file and write it to a textbox one line at a time. After writing one line, I want to do some if- then stuff and then write the next line. I can easily write one line using the sr.steamline but everytime I embed an if-then statement, I get exceptions.
My goal is just to do this:
Read a file
Write one line
If "shall" is in the line then put the line in a temporary string
Go to the next line until the document is done.
-
Nov 1st, 2003, 06:09 PM
#2
here's a quick example ...
VB Code:
[Color=Blue]Dim[/COLOR] sReader [Color=Blue]As[/COLOR] [Color=Blue]New[/COLOR] IO.StreamReader([Color=Blue]New[/COLOR] IO.FileStream("C:\test.txt", IO.FileMode.Open))
[Color=Blue]Dim[/COLOR] strLine [Color=Blue]As[/COLOR] [Color=Blue]String
[/COLOR] [Color=Blue]While[/COLOR] [Color=Blue]Not[/COLOR] sReader.Peek
strLine = sReader.ReadLine [Color=Green]'///[/COLOR] [Color=Green]make[/COLOR] [Color=Green]the[/COLOR] [Color=Green]string[/COLOR] [Color=Green]strLine[/COLOR] [Color=Green]hold[/COLOR] [Color=Green]the[/COLOR] [Color=Green]current[/COLOR] [Color=Green]line[/COLOR] [Color=Green]of[/COLOR] [Color=Green]text[/COLOR] [Color=Green]being[/COLOR] [Color=Green]read[/COLOR] [Color=Green].[/COLOR] [Color=Green]
[/COLOR] [Color=Blue]If[/COLOR] [Color=Blue]Not[/COLOR] strLine.IndexOf("shall") = -1 [Color=Blue]Then[/COLOR] [Color=Green]'///[/COLOR] [Color=Green]if[/COLOR] [Color=Green]the[/COLOR] [Color=Green]line[/COLOR] [Color=Green]contains[/COLOR] [Color=Green]the[/COLOR] [Color=Green]word[/COLOR] [Color=Green]"[/COLOR] [Color=Green]shall[/COLOR] [Color=Green]"
[/COLOR] [Color=Green]'///[/COLOR] [Color=Green]do[/COLOR] [Color=Green]stuff[/COLOR] [Color=Green].[/COLOR] [Color=Green]
[/COLOR] [Color=Blue]End[/COLOR] [Color=Blue]If
[/COLOR] [Color=Blue]End[/COLOR] [Color=Blue]While
[/COLOR] sReader.Close()
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|