File Search

PureSc0pe

Well-known member
Joined
Mar 17, 2004
Messages
161
Location
Arizona
The following text file search only half works. Here is an example of something I would be searching: Alex:12.34.56.78 When I search by Alex, it displays the results. However if I search by 12.34.56.78, it says No Results Found. Why is it only working when I search by the name and not when I search by the numbers as well? Please Help.

VB Code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Clear()
Dim str, any, str2 As String
Dim sr As System.IO.StreamReader
Dim prog As System.IO.File
any = TextBox1.Text
sr = prog.OpenText(TextBox2.Text)
While sr.Peek <> -1
str = sr.ReadLine
str2 = str.Substring(0, TextBox1.Text.Length)
If any.ToLower = str2.ToLower Then
ListBox1.Items.Add(str)
End If
End While
If ListBox1.Items.Count = 0 Then
MessageBox.Show("No Results Found", "Program V 1.0",
MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Sub
 
Because you are checking the string with Substring... for instance if you wanted to find "12.34.56.78" in "Alex:12.34.56.78", then with Substring, youd be doing this:
"Alex:12.34." (The first 11 characters of the string) against
"12.34.56.78"
Instead, you need to use IndexOf to determine if it is in the string.
If "Alex:12.34.56.78".IndexOf("12.34.56.78") >= 0 Then its in the string. :)
 
Iceplug said:
Because you are checking the string with Substring... for instance if you wanted to find "12.34.56.78" in "Alex:12.34.56.78", then with Substring, youd be doing this:
"Alex:12.34." (The first 11 characters of the string) against
"12.34.56.78"
Instead, you need to use IndexOf to determine if it is in the string.
If "Alex:12.34.56.78".IndexOf("12.34.56.78") >= 0 Then its in the string. :)

I dont quite understand how you would substitute that into my coding. I tried and couldnt make much sense of it.
VB Code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Clear()
Dim str, any, str2 As String
Dim sr As System.IO.StreamReader
Dim prog As System.IO.File
any = TextBox1.Text
sr = prog.OpenText(TextBox2.Text)
While sr.Peek <> -1
str = sr.ReadLine
If "TextBox1.Text".IndexOf("TextBox1.Text") >= 0 Then
any.ToLower = str2.ToLower
ListBox1.Items.Add(str)
End If
End While
If ListBox1.Items.Count = 0 Then
MessageBox.Show("No Results Found", "Program V 1.0", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Sub
 
No...
the .IndexOf() is a property of a string. You can use it to find a location of a substring in a string, or if it is in the string.

Example:
Code:
str = "Alex:12.34.56.78"
TextBox.Text = "34.56"
If str.IndexOf(TextBox.Text) >= 0 Then something
checks to see if "34.56" is in the string "Alex:12.34.56.78"
it is located starting at the 9th character (which is 8 starting from 0)
so the .IndexOf() method will return 8... which is >= 0.
TextBox.Text = "bumpy"
If str.IndexOf(TextBox.Text) >= 0 Then something
IndexOf will return -1 since bumpy is not in the string above.
1 is not >= 0, so the if statement does not execute
TextBox.Text = "Alex"
IndexOf will return 0, since Alex is the first thing in the string, it starts
from character 0, and 0 is >= 0, so the If statement executes.
 
I think Im becoming more and more lost with each post. I cant figure out how to put this into my code.... Bold = Errors

VB Code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Clear()
Dim str, any, str2 As String
Dim sr As System.IO.StreamReader
Dim prog As System.IO.File
any = TextBox1.Text
sr = prog.OpenText(TextBox2.Text)
While sr.Peek <> -1
str = "TextBox2.Text"
TextBox1.Text = ""
If str.IndexOf(TextBox1.Text) >= 0 Then something()

TextBox2.Text = "bumpy"
If str.IndexOf(TextBox1.Text) >= 0 Then something()

TextBox2.Text = "TextBox1.Text"
ListBox1.Items.Add(str)
End While
If ListBox1.Items.Count = 0 Then
MessageBox.Show("No Results Found", "PureSc0pes IP Searcher V 1.0", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Sub
 
No, that was just an example-demo program. I didnt mean for you to actually cut and paste what I wrote into the program... I am writing it so that you will understand what I am doing. All I originally asked you to do was replace the .Substring line and the If Then statement line checking the strings with an If Then statement line checking IndexOf. :)
If str.IndexOf(TextBox1.Text) >= 0 Then
 
Iceplug said:
No, that was just an example-demo program. I didnt mean for you to actually cut and paste what I wrote into the program... I am writing it so that you will understand what I am doing. All I originally asked you to do was replace the .Substring line and the If Then statement line checking the strings with an If Then statement line checking IndexOf. :)
If str.IndexOf(TextBox1.Text) >= 0 Then

Wow, Im dumb...just figured that out :D Thanks, it works...
 
Back
Top