findOneOf

Finds the first occurrence of any one of a set of characters in a string, from a specified start position. The search is case-sensitive.

Returns the position of the first member of set found in string; or 0, if no member of set is found in string.

findOneOf(set, string [, start]) → returns numeric

Argument Reference

set string
Required

String which contains one or more characters to search for.

string string
Required

String in which to search.

start numeric
Default: 1

Start position of search. Can be 1 through the length of the string to search. Choosing a start index greater than the length of the string to search will return a 0.

Examples
Sample code invoking the findOneOf function

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

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

Expected Result: 7

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

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

Expected Result: 16

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.

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

Expected Result: 3

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub