Parsing a flat file to retrieve only a single line.

  • Thread starter Thread starter mwazir
  • Start date Start date
M

mwazir

Dear all,

I have a requirement while parsing a delimited flat file and I was wondering
if there is a simpler solution that what I have in mind.
Basically I need to pull out a line from the flat file and the information I
am given is the line number and the name of the file. Therefore I have
thought of implementing something like this.

Private Function getLineFromFile(ByVal sFilePath As String, ByVal
lStringNo As Long) As String

Dim oStream As New IO.StreamReader(sFilePath)
Dim strReadLine As String = "", strReturnValue As String = ""
Dim lLine As Long = 0

While (oStream.Peek() > -1)
lLine = lLine + 1
strReadLine = oStream.ReadLine()
If lLine = lStringNo Then
strReturnValue = strReadLine
Exit While
End If
End While

oStream.Close()
oStream = Nothing
Return strReturnValue
End Function

Another factor I am keeping in mind is that the files can have between 50 to
2000 lines. Appreciate any thoughts you may have.

Many thanks
 
is there a particular value or information that you're looking for in the
file or is it just some text in some random line number?

Just some text in some random line.
 
Back
Top