O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

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, InStrB Functions

Syntax

InStr([start, ]stringtosearch, stringtofind[, comparemode])
start

Use: Optional

Data Type: Numeric

The starting position for the search.

stringtosearch

Use: Required

Data Type: String

The string being searched.

stringtofind

Use: Required

Data Type: String

The string being sought.

comparemode

Use: Optional

Data Type: Integer

The type of string comparison.

Return Value

A Long.

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 stringtosearch and stringtofind, as shown in the following table:

Condition

InStr return value

stringtosearch is zero-length

0

stringtosearch is Null

Null

stringtofind is zero-length

start

stringtofind is Null

Null

stringtofind is not found

0

stringtofind is found within stringtosearch

Position at which the start of stringtofind is found

start > len(stringtofind)

0

  • If the start argument is omitted, InStr commences the search with the first character of stringtosearch.

  • If the start argument is Null, an error occurs.

  • You must specify a start argument if you are specifying a comparemode argument.

  • VBScript supports intrinsic constants for comparemode, as follows:

    Comparison mode

    Value

    Constant

    Binary (default)

    0

    vbBinaryCompare

    Text—case- insensitive

    1

    vbTextCompare

    In effect, a binary comparison means that the search for stringtofind in stringtosearch is case-sensitive. A text comparison means that the search for stringtofind in stringtosearch is not case-sensitive. ...

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