InStr Function in VB.NET

What is the use of InStr function in VB.NET?


InStr Function

Instr String Function in Visual 2008 is used to find the starting position of a substring inside a string.

Function InStr(ByVal Start As Integer,ByVal String1 As String,
ByVal String2 As String, Optional ByVal Compare As
CompareMethod) As Integer

In the above syntax Start specifies the starting position for the search, String1 specifies the string to search, the substring specifed as String2. The Compare function specifies the type of comparison to be followed.

Module Module1
Sub Main()
Console.WriteLine("Starting index of HI in the string
is::" & InStr("HI THIS IS CA CLUB", "HI"))
End Sub
End Module

Starting index of HI in the string is::1

In the above example, the Instr function returns 1 as the substring 'HI' is in the begining of the string.

Visual Basic Tutorial

Ask Questions

Ask Question