find Method

Class: String

Description

This method locates the next position of a string. This method replaces the $FIND() function.

Syntax

StringObject.find(String find,Number start,Boolean ignoreCase,

String quoteChar)

Parameters

find

The string for which to search. If absent or empty, the method returns the implied value of the start parameter, regardless of the values of the other arguments. (The empty string is located immediately before the start position.)

start

The character position at which to start the search (e.g., 1 denotes the first character, etc.). If you specify a value less than 1, the method uses 1. The default is 1.

ignoreCase

An option that indicates whether the search ignores case. Valid values are 1 (ignore case) and 0 (do not ignore case). The default is 0.

quoteChar

The quote character. Substrings enclosed by the quote character are ignored. If this parameter is not supplied, or if the empty string is supplied, no special treatment of a quoted substring occurs.

Returns

A Number that specifies the position of the character that follows the find string. If the string is not found, zero is returned.

When Became Available

v7.0

Example

type String STR = "Behold! ""Be"" happy, be free"

 

type Number N1 = STR.find("Be")      //  3

type Number N2 = STR.find("Be",1)    //  3

type Number N3 = STR.find("Be",5)    // 12

type Number N4 = STR.find("Be",15)   //  0

 

// example with ignoreCase=1

type Number NC = STR.find("Be",15,1) // 23

 

// examples with ignoreQuoted=1

type Number NQ = STR.find("Be",5,0,1) //  0

type Number NB = STR.find("Be",5,1,1) // 23