|
-
Dec 11th, 2006, 10:54 AM
#1
Thread Starter
Addicted Member
[RESOLVED] [2005] How to read a block of text line by line?
Hi,
I mainly process text files and if I need to run through the file twice, I'll open and read through the file twice, line by line, picking out the info I need.
I know this is inefficient. I was thinking of reading a text file line by line and putting each line into a List of String and then I could reprocess using that.
Or could a text file be read as a block, e.g. IO.ReadAllText(), and somehow processed line by line?
What do you suggest? I mentioned twice above, but actually it might be up to a dozen times.
Thx for your tips.
-
Dec 11th, 2006, 11:19 AM
#2
Re: [2005] How to read a block of text line by line?
You could simply split the contents by each new line if that's what always happens in your text file, or similarly the symbol that marks the end of each line.
Load each into a string array:
VB Code:
Dim myStr() As String = My.Computer.FileSystem.ReadAllText("D:\My Documents\MyExample.txt").Split(Environment.NewLine)
That will place each line of your text file into an array.
-
Dec 11th, 2006, 07:53 PM
#3
New Member
Re: [2005] How to read a block of text line by line?
I would say the following is a tad more efficient, at the very least smaller, than the above:
VB Code:
Dim aList() As String = System.IO.File.ReadAllLines("C:\Test.txt")
-
Dec 11th, 2006, 08:08 PM
#4
Thread Starter
Addicted Member
Re: [2005] How to read a block of text line by line?
Waha! So that's what RealAllLines is for. Doh.
Thx both for your help.
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
|