Home » VB.NET Basics » 05 - Strings
5

String Position

How to locate string position

With VB .NET, you can locate a string within a string. The command used to identify a string within a string is the InStr() command. See the code below and see how it works.


        Dim Result As Integer

        Result = InStr("Display", "p")

        MsgBox(Result)

The result returns a value of 4 because "p" is the fourth occurrence on the string. Try changing "p" to "isp" and see what happens. The general structure of the InStr() command is shown below.


Instr("[string to look at]","[string to be look for]")