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
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