find, find ignore case, find ignore blanks, find ignore both
Searches the string for specified patterns and returns the character position number (0 = 1st character).
Indirect parameter passing is disabled
2-4
No. | Type | Description |
---|---|---|
1 input |
valid types | input string or value Attention: If 1st parameter is a set, please refer to find [set function] instead. Values of types other than string will be converted to strings first. |
2 input |
valid types | matching pattern String to search for. If the parameter of type set, see description in nexdt box below. Values of other types (e.g. numerals) are converted to strings. |
Alt. 2 input |
set | matching patterns List of multiple matching patterns. Non-string contents in the set will be converted to strings. With multiple matching patterns available, the first match will be identified and returned. Here, no wildcards are supported. |
Opt. 3 input |
numeral | starting position Specify starting position to search. Eg. 1 excludes the 1st character in the string. |
Opt. 4 output |
numeral | pattern number Returned pattern number (provided 2nd parameter is a set and 1st paraemter is not a set) Default value: 0 |
Type | Description |
---|---|
numeral | Character position number Positive or zero: Found and position number returned. -1: Not found. |
st[] = "We ate pizza, pasta and desert delights like gelati, and conclude with a caffè.";
// 1st two finds point on 'pizza', the 3rd fine points to 'pasta'
echo( "Testing '", st[], "':" );
// Examples include quoted (1st 2 examples) and softquoted strings (last 2 examples)
echo( find( st[], "pizza" ), " / ", find( st[], "p???a" ), " / ", find( st[], 'p???a' ), " / ", find( st[], 'p???a', 10 ) );
echo( "Looking for Desert: ", find ignore case( st[], "Desert" ) );
echo( "Ignore spaces: ", find ignore both( st[], "pizza,PASTA" ) );
echo( "No match case: ", find ( st[], "pizza,PASTA" ) );
// Demonstrate use of non-string values:
// In 1st case, it's a numeral with preserved string, 2nd case it's a plain numeral after a calculation
echo( "Locating a digit: ", find ( 00001234.56, 34, 0 ), " / ", find ( 0 + 00001234.56, 34, 0 ) );
foods[] = { Gelati, Pizza, Pasta, Caffè };
index[] = -1;
for ( i[] = 1, i[] <= 4, i[] ++ )
{
index[] = find ignore case( st[], { gelati, pasta, desert }, index[]+1, choice[] );
echo ( i[], ". order is ", foods[]{choice[]} );
}
Testing 'We ate pizza, pasta and desert delights like gelati, and conclude with a caffè.':
7 / -1 / 7 / 14
Looking for Desert: 24
Ignore spaces: 5
No match case: -1
Locating a digit: 6 / 2
1. order is Pizza
2. order is Pasta
3. order is Gelati
4. order is Caffè