|
-
Jul 19th, 2005, 07:23 AM
#1
Thread Starter
Lively Member
[RESOLVED] Read Line Number X
Ive got an array of numbers, and I need to go through it, and grab information from lines of a text file, that correspond to the numbers in this array...
EG:
Array(1,5,10,12)
I want to read in order:
Line 1
Line 5
Line 10
Line 12
Now I can do the loop bit, but I am unsure on how to go to Line X and read all the information from that line. Anyone able to help me out?
Cheers
-
Jul 19th, 2005, 08:34 AM
#2
Re: Read Line Number X
I think there's no alternative but using StreamReader.ReadLine method?
Regards
Jorge
"The dark side clouds everything. Impossible to see the future is."
-
Jul 19th, 2005, 08:39 AM
#3
Thread Starter
Lively Member
Re: Read Line Number X
Yes, but how do I get that to read line number X ?
Can you post an example for me please?
-
Jul 19th, 2005, 08:57 AM
#4
Re: Read Line Number X
VB Code:
Public Function GotoLine(ByVal filename As String, ByVal line As Int32) As String
Dim fs As New StreamReader(filename)
Dim aLine As String = String.Empty
Dim counter As Int32 = 0
Try
Do
aLine = fs.ReadLine
counter += 1
If counter = line Then Exit Do
Loop Until aLine Is Nothing
Catch ex As Exception
''MessageBox.Show(ex.Message)
End Try
fs.Close()
Return aLine
End Function
"The dark side clouds everything. Impossible to see the future is."
-
Jul 19th, 2005, 09:34 AM
#5
Thread Starter
Lively Member
Re: Read Line Number X
Sorted. Didn't think about using a loop, having a blonde day...
Cheers
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
|