abhit_kumar
Member
- Joined
- Aug 13, 2008
- Messages
- 19
- Programming Experience
- Beginner
Hello Frnd,
I get stuck in one of the programme.
when we r trying to serach line number in txt file, and if txt file having only single column data then it returns correct line number, but if in txt file there is more than one column data then it deoesnt work..
For example:- txt file contain following patter of data
111 anil 222
333 ajit 444
555 anish 666
777 ankit 888
999 ajay 999
And suppose if we have to search data 444, its ocurring on 2nd line, but this code returns incorrect line no.
Also look at last line, there is data 999(on 3rd column), but since this line also occuring 999 on first column, in that case its also not working...
Based upon your code and some my modication, i have trying to resolve this issue, but cant get proper solution for above issues.
My code is as follows:-
I get stuck in one of the programme.
when we r trying to serach line number in txt file, and if txt file having only single column data then it returns correct line number, but if in txt file there is more than one column data then it deoesnt work..
For example:- txt file contain following patter of data
111 anil 222
333 ajit 444
555 anish 666
777 ankit 888
999 ajay 999
And suppose if we have to search data 444, its ocurring on 2nd line, but this code returns incorrect line no.
Also look at last line, there is data 999(on 3rd column), but since this line also occuring 999 on first column, in that case its also not working...
Based upon your code and some my modication, i have trying to resolve this issue, but cant get proper solution for above issues.
My code is as follows:-
VB.NET:
Imports System
Imports System.IO
Public Class Form1
Dim storeLineNo As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = ""
Dim fs As FileStream
fs = New FileStream(Path.Combine(Application.StartupPath, "\testdr.txt"), FileMode.Open, FileAccess.Read)
Dim sr As StreamReader
sr = New StreamReader(fs)
Dim strLine As String = String.Empty
Dim intLineCount As Integer = 1
Dim LineNo As Integer = 0
While (sr.Peek() > -1)
LineNo = LineNo + 1
strLine = Convert.ToString(sr.ReadLine())
If (strLine.Equals(TextBox1.Text)) Then
storeLineNo += LineNo & ","
End If
End While
If (storeLineNo = String.Empty) Then
Label1.Text = ""
Else
Label1.Text = storeLineNo.ToString()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Label1.Text = ""
End Sub
End Class