In VB, InStr(string1,string2[,CompareMethod]) is used to find a string in another string. It returns the position of the first match.
-string1 is the string being searched.
-string2 is the string sought
-CompareMethod is an optional argument. I takes one of the two constant values--CompareMethod.Binary or CompareMethod.Text. If you specify CompareMethod.Binary, the comparison is case-sensitive. This means that ab is not the same as Ab, aB, or AB. By using CompareMethod.Text, the comparison is case-insensitive. If the string2 is not in string1, the function returns 0. Otherwise, it returns the position of the first match of string2
Dim str1 As String = "VB programming language"
Dim str2 As String = "Programming"
Dim pos = InStr(str1, str2, CompareMethod.Binary)
If Not (pos = 0) Then
MsgBox(str2 & " is found at position " & pos & " in " & str1 & ".")
MsgBox(str2 & " is not found in " & str1 & ".")
Posted by: Dara | post date: 02-15-2013 | Subject: VB.NET Programming Language
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages: