[Resolved][2008]Find String In String IndexOf("flowers")
Hi
The problem is that the code cant find word flowers from *.txt file. I added msgbox & looped all 5 lines & I see that the flowers are there. if i change flowers to BIOS, then the code will find the word. So im little lost hire, Why it cant find flowers?
Code:
Dim myOpenFileDialog As New OpenFileDialog()
myOpenFileDialog.CheckFileExists = True
myOpenFileDialog.DefaultExt = "txt"
myOpenFileDialog.InitialDirectory = "C:\"
myOpenFileDialog.Multiselect = False
If myOpenFileDialog.ShowDialog = DialogResult.OK Then
Dim a() As String = Split(My.Computer.FileSystem.ReadAllText(myOpenFileDialog.FileName), Environment.NewLine)
Dim r As Integer
Dim i As Integer
For i = 0 To a.GetUpperBound(0)
r = a(i).IndexOf("flowers")
If r > 0 Then ' if found flowers
MsgBox("Found word,:" & a(i))
Exit For
End If
Next
End If
*txt file contents:
Code:
[BIOS]
Ver=AB60S00P
[BIOS]
Ver=AB60S00P
flowers
Re: [2008]Find String In String IndexOf("flowers")
this statement If r > 0 Then is your problem.
What does IndexOf return?
Re: [2008]Find String In String IndexOf("flowers")
Quote:
Originally Posted by dbasnett
this statement If r > 0 Then is your problem.
What does IndexOf return?
aa now I get it. From the example Discription i took it from, the IndexOf should return 0 if no match. But in reality it returns Negative nr if no match.
Thank you. It seems to be working now, just changed if r > 0 to If r >= 0