Returns a number that represents the position of a string within another string.

Syntax

<target expC>.indexOf(<search expC> [, <from index expN>])

<target expC>

The string in which you want to search for <search expC>.

<search expC>

The string you want to search for in <target expC>.

<from index expN>

Where you want to start searching for the string. By default, dBASE Plus starts searching at the beginning of the string, index 0.

Property of

String

Description

This method is similar to the AT( ) function, but in addition to the syntactic difference of being a method instead of a function and the fact that the position is zero-based, the optional parameter specifies where to start searching instead of the nth occurrence to find.

indexOf( ) returns an index representing where a search string begins in a target string. The first character of the string is at index 0 and the last character is at index <target expC>.length – 1. indexOf( ) searches one character at a time from left to right, beginning to end, from the character at <from index expN> to the last character. The search is case-sensitive. Use toUpperCase( ) or toLowerCase( ) to make the search case-insensitive.

indexOf( ) returns –1 when

The search string isn’t found.

The search string or target string is empty.

The search string is longer than the target string.

Use lastIndexOf( ) to find the starting position of <search expC>, searching from right to left, end to beginning.