Previous Topic

Next Topic

InStr - MaxBasic Function

InStr([Start: Number, ]String1: String, String2: String): Number

String position. Returns the position of the start of the first instance of String2 contained within String1, searching from position Start. If String2 is not found in String1 or String1 is zero length, 0 is returned. If String2 is zero length, Start is returned, or 1 when Start is not given. If Start is greater than the length of String1, 0 is returned. If either string argument is null, null is returned.

This topic describes InStr with MaxBasic VB compatibility selected, which is the default and is recommended. See MaxBasic VB Compatibility.

Instr function syntax has these named arguments:

Parameter

Description

Start

Optional. Position in String 1 where the search starts. Must be 1 or greater. When not given, the search starts at position 1.

String 1

Required. String to be searched for String 2.

String 2

Required. String to search for in String 1.

Sample code:

  Print Instr("caterpillar", "pill")

Returns: 6

  Print InStr(4, "abcabc", "b")

Returns: 5

When VB compatibility is not selected

When MaxBasic VB compatibility is not selected on System Settings - General tab, and the script has no Option VBCompatibility statement, InStr without Start returns 0 when String2 is zero length.

See Also

String Functions

Book Contents

Book Index