O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

InStr Function

Class

Microsoft.VisualBasic.Strings

Syntax

InStr(start, string1, string2[, compare])

or:

InStr(string1, string2[, compare])
start (required in first syntax; Numeric)

The starting position for the search

string1 (required; String)

The string being searched

string2 (required; String)

The string being sought

compare (optional; CompareMethod enumeration)

The type of string comparison

Return Value

An Integer indicating the position of the first occurrence of string2 in string1

Description

Finds the starting position of one string within another

Rules at a Glance

  • The return value of InStr is influenced by the values of string1 and string2, as the following table details:

Condition

InStr return value

string1 is zero-length or Nothing

0

string2 is zero-length or Nothing

start

string2 not found

0

string2 found within string1

Position at which the start of string2 is found

start > len(string2)

0

  • In the second syntax, InStr commences the search with the first character of string1.

  • If the start argument is 0 or Nothing, an error occurs.

  • The compare argument can be one of CompareMethod.Binary (a case- sensitive comparison) or CompareMethod.Text (a case-insensitive comparison). If comparemode is omitted, the type of comparison is determined by the Option Compare setting.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required