Vicon Shogun banner

Description

Tries to find a sub-string within another string, and returns the zero-based index of the first character of the sub-string in string. If the sub-string is not found, -1 is returned.

Functional area

String

Command syntax

Syntax

strFind "string" "subString" index

Arguments

NameTypeRequiredComments
stringstringyesString to be searched.
subStringstringyesSub-string to be searched for with "string" argument.
startIndexintegeryesZero-based index of the character of string to start searching at, or 0 to search from the beginning.

Flags

None

Return value

integer

Returns the zero based index of the location of the first character of the sub-string found. Returns -1 if not found.

Examples

// Search for a substring
string $str = "This is some text";
int $index;

// Search for the word "some"
$index = `strFind $str "some" 0`;
print $index;
// Should be 8

// Search for the word "texas"
$index = `strFind $str "texas" 0`;
print $index;
// Should be -1

// Search for the letter "t" after the word "some"
$index = `strFind $str "t" 12`;
print $index;
// Should be 13

Additional information

Related commands