Tag Archives: search string

Check for a specific String in a String in VB.NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

This works for VB.NET and higher.


        'Will check a string to see if it contains a specified string.
        'The string that will be searched.
        Dim str As String = "This string has some text"
        'The string to find.
        Dim i As Integer = str.IndexOf("string")
        'If it returns -1 it means that no matches for the specified string was found.
        If Not i = -1 Then

            MessageBox.Show("Yeps, that string is in here!")


            MessageBox.Show("No, the string is not in here!")

        End If