FindOneOf

Finds the first occurrence of any character in a set of characters, from a specified start position.

Method Signature

FindOneOf(set=[string], string=[string], start=[integer])

Arguments

Argument
Type
Required
Description
Default

set

string

true

The set of characters to search for the first occurrence of.

string

string

true

The string to search in.

start

integer

false

The position from which to start searching in the string. Default is 1.

1

Examples

Find first instance starting from beginning of string.

We're not passing a start index in this example.

Run Example

string_to_search = "The rain in Spain falls mainly in the plains.";
writeOutput( findOneOf( "in", string_to_search ) );

Result: 7

Find first instance starting from the twelfth character.

Let's pass in a starting index of 12. The search will start at the twelfth character, just before the word 'Spain'.

Run Example

string_to_search = "The rain in Spain falls mainly in the plains.";
writeOutput( findOneOf( "in", string_to_search, 12 ) );

Result: 16

Example showing this function will search all characters from the 'set' argument in the 'string' argument.

This function is case-sensitive so 't' does NOT match the first 'T'. It's the same for 'H' NOT matching the first 'h'. But 'e' matches the 'e' at the third position. Since this is the first match, this is the index that is returned.

Run Example

string_to_search = "The rain in Spain falls mainly in the plains.";
writeOutput( findOneOf( "tHe", string_to_search, 1 ) );

Result: 3

Additional Examples

Run Example

dump( FindOneOf( "a", "a a a a b b b b" ) );
dump( FindOneOf( "b", "a a a a b b b b" ) );
dump( FindOneOf( "c", "a a a a b b b b" ) );

Last updated

Was this helpful?