Question Search "words with mark" in txt file?

titanotam

New member
Joined
May 26, 2009
Messages
1
Programming Experience
Beginner
i want to search "words with mark" in txt file.
For example: i want to search: "tâm" in my txt file. but my code couldn't find that word, it could find a word "tam"
Please help me!

Here is my code:

''Button search
VB.NET:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If FindStringInFile("link to my txt file", "word with mark") Then
            MessageBox.Show("found")
        Else
            MessageBox.Show("not found")
        End If
End Sub

'' Search Function
VB.NET:
Public Function FindStringInFile(ByVal Filename As String, ByVal SearchString As String) As Boolean
        Dim Reader As System.IO.StreamReader
        Reader = New IO.StreamReader(Filename)
        Dim stringReader As String
        Try
            While Reader.Peek <> -1
                stringReader = Reader.ReadLine()
                If InStr(stringReader, SearchString) > 0 Then Return True
            End While
            Reader.Close()
            Return False
        Catch ex As Exception
            MessageBox.Show("Exception: " & ex.Message)
            Return False
        End Try
End Function
 
You are returning a result before you read the entire file.

Use ReadToEnd() to read the entire contents of a file.
 
Back
Top