Find String Within Text File
Find String Within Text File
Find String Within Text File
Find String Within Text File
Find String Within Text File
Find String Within Text File Find String Within Text File Find String Within Text File Find String Within Text File Find String Within Text File Find String Within Text File Find String Within Text File Find String Within Text File
Find String Within Text File Find String Within Text File
Find String Within Text File
Go Back  Xtreme Visual Basic Talk > > > Find String Within Text File


Reply
 
Thread Tools Display Modes
  #1  
Old 05-25-2008, 10:38 AM
Glj12 Glj12 is offline
Centurion
 
Join Date: May 2005
Posts: 109
Unhappy Find String Within Text File


I am trying to view if a certain string from textbox3.text is found within a certain text file. This is what I have, yet, it always returns with a msgbox saying that it did find it in there, when it actually is not. Ideas?

Code:
        Dim YourString As String = IO.File.ReadAllText("traverse_history.txt")
        Dim MatchString As String = TextBox3.Text

        If YourString.IndexOf(MatchString) <> 0 Then
            MsgBox(TextBox3.Text & " was found within the traversal")
            Shell("taskkill /IM ""Web Traversal Console.exe"" /F")
            Timer1.Enabled = False

        Else
            MsgBox(TextBox3.Text & " was NOT found within the traversal")
            Shell("taskkill /IM ""Web Traversal Console.exe"" /F")
            Timer1.Enabled = False

        End If
Reply With Quote
  #2  
Old 05-25-2008, 12:05 PM
AtmaWeapon's Avatar
AtmaWeaponFind String Within Text File AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

0 is the first character in the string, thus it is a valid index that can be returned from String.IndexOf. The String.IndexOf documentation wrote the rest of the post for me:
Quote:
Return Value
Type: System.Int32

The index position of value if that string is found, or -1 if it is not. If value is Empty, the return value is 0.
You should be comparing to -1, not 0.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 05-25-2008, 01:03 PM
Glj12 Glj12 is offline
Centurion
 
Join Date: May 2005
Posts: 109
Default

Thank you so much, cheers!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Find String Within Text File
Find String Within Text File
Find String Within Text File Find String Within Text File
Find String Within Text File
Find String Within Text File
Find String Within Text File Find String Within Text File Find String Within Text File Find String Within Text File Find String Within Text File Find String Within Text File Find String Within Text File
Find String Within Text File
Find String Within Text File
 
Find String Within Text File
Find String Within Text File
 
-->