search string in a textfile

tergerregret

New member
Joined
Feb 21, 2006
Messages
3
Programming Experience
3-5
hi,
in my form, i have one textbox and a button that browse for textfile. then, i have another text box, and a 'search' button. i want user to first browse for a *.txt file, and then put a text into the second textbox, and press the 'search' button. the system then should indicate whether the text searched was in the textfile or not.
is this system possible? i mean. is there any way i can do such searching?
 
in the 1st textbox (the one with the contents of the file) i think you can use the Equals method to see if the textbox has the value that's in the 2nd textbox
 
Sample Code and snapshots

I do not know how good this code is. I was bored and did it real quick. I am including snapshots of the screen as attachments. Just one way to do what you described...



Imports System.io
PublicClass Form1
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim hold AsString = ""
Dim x AsInteger = 0
Dim count AsInteger = 0
If TextBox1.Text <> ""Then
Dim SR As StreamReader
SR = File.OpenText(TextBox1.Text)
hold = SR.ReadToEnd()
x = hold.IndexOf(TextBox2.Text)
DoWhile x >= 0
count = count + 1
x = hold.IndexOf(TextBox2.Text)
hold = Mid(hold, x + TextBox2.Text.Length + 1)
Loop
EndIf
Label3.Text = "Found " & count.ToString & " Times"
Label2.Refresh()
EndSub
PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Application.Exit()
EndSub
End
Class
 

Attachments

  • pc_capture1.jpg
    pc_capture1.jpg
    15.2 KB · Views: 72
  • pc_capture2.jpg
    pc_capture2.jpg
    17 KB · Views: 72
  • pc_capture3.jpg
    pc_capture3.jpg
    17.3 KB · Views: 69
Back
Top