indexOf()
The strLib.indexOf() system function returns an index into a string of characters; the index indicates where a specified pattern begins.
Syntax
strLib.indexOf(
source STRING | UNICODE | CHAR | DBCHAR | MBCHAR inOut,
pattern STRING | UNICODE | CHAR | DBCHAR | MBCHAR in
[, skipCount INT in] )
returns (result INT)
- source
- Input can be any value that is assignment compatible with the types shown.
- pattern
- A sequence of characters that EGL searches for in source. The value must be the same type as source.
- skipCount
- The number of initial characters in source to ignore before beginning the search for pattern. If this value is not valid (less than 0 or greater than the length of source), the function throws an IndexOutOfBounds exception.
- result
- The index of the beginning of pattern within source. If pattern is not found, the function returns 0.
Example 1
The following example locates the first two occurrences of a semicolon in the source string:
source STRING = "STRING; CHAR; DBCHAR; MBCHAR; or UNICODE.";
pattern STRING = "; "
result = strLib.indexOf(source, pattern);
// result is 7
result = strLib.indexOf(source, pattern, 10);
// result is 13
Example 2
The following example locates all occurrences of blanks in the source string:
function indexOfExample()
text string = "A BC DEF GHIJ" ;
pIndex int = indexOf(text, " ", 0);
while(pIndex != 0);
writeStdOut("Blank index = " + pIndex);
pIndex = indexOf(text, " ", pIndex);
end
end
The console displays the following lines:
Blank index = 2
Blank index = 5
Blank index = 9