Check for a specified String in a String (VS2003) ' '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!") Else MessageBox.Show("No, the string is not in here!") End If
(VS2005) 'Check if a String contains a specified string. ' Dim str As String = "This string has some text" If str.Contains("string") Then MessageBox.Show("Yeps, that string is in here!") Else MessageBox.Show("No, the string is not in here!") End If
|