InStr Function

Find the index of the first occurrence of a string within another.

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

Parameters

Start  -  (Input, expression, Optional)

Specifies the starting character index for the search. If omitted, the search begins at the first character. The first character position is index 1. The comma is still required if this parameter is omitted. If this parameter is a string, it will be converted to numeric form first. If negative, the result is Error.

String1  -  (Input, expression, Required)

Specifies the string expression to be searched.

String2  -  (Input, expression, Required)

Specifies the sub-string expression that you wish to search for. If a numeric expression is passed, it is first converted into a string, otherwise, if a non-string is passed, the result is Error.

anycase  -  (Input, expression, Optional)

If True, a non case-sensitive search is performed, otherwise a case-sensitive search is performed. If omitted, case is assumed to be False.

Return Value

Returns the index of where the sub-string (string2) was found. If the sub-string could not be found, zero is returned.

Examples

InStr (1, “ABCD”, “bc”)

Returns 0

InStr (1, “ABCD”, “bc”, False)

Returns 0

InStr (1, “ABCD”, “bc”, True)

Returns 2

InStr (1, “ABCD”, “BC”)

Returns 2

InStr (1, 1234, 23)

Returns 2

InStr (-1, “ABCD”, “BC”)

Returns Error

InStr (3, “ABCD”, “BC”)

Returns 0

InStr (1, “ABCD”, Null)

Returns Error

InStr (1, Error, “BC”)

Returns Error

TIP:

Functions are specifically for use in the Macro Editor. Refer to Microsoft's official VB and JScript documentation for scripting equivalents.

See Also

Functions | Asc function | Chr function | CSet function | Format function | InStr function | LCase function | Left function | Len function | LSet function | LTrim function | Mid function | Replace function | Right function | RSet function | RTrim function | Space function | String function | TCase function | Trim function | UBound function | UCase function


© 2004-2021 looksoftware. All rights reserved.