Xbasic

*AT_MULTI Function

Syntax

Position as N = *AT_MULTI(C find_strings, C search_in_string [,N occurrence])

Arguments

find_stringsCharacter

A CR-LF delimited string containing one or more strings to find.

search_in_stringCharacter

The character string to examine.

occurrenceNumeric

Default = 1. The occurrence to find.

Returns

PositionNumeric

Returns the position where the occurrence of a string in find_strings is found. Returns zero if none of the strings are found in the search_in_string.

Description

Returns the position where one of a CR-LF delimited list of strings is found in another.

Discussion

The *AT_MULTI() function performs a case-insensitive search of multiple search strings in a string. The function returns the index where the first match of the search strings are found. The index of the first match is returned unless otherwise specified using the occurrence parameter. If multiple matches exist in the string, the occurrence parameter can be used to get the index of each additional match.

Example

' Return the first occurrence
? *at_multi(comma_to_crlf("oranges,apples"),"This string contains apples and oranges") = 22 

' Returns the second occurrence
? *at_multi(comma_to_crlf("oranges,apples"),"This string contains apples and oranges",2) = 33 

' Returns the third occurrence (which doesn't exist)
? *at_multi(comma_to_crlf("oranges,apples"),"This string contains apples and oranges",3) = 0

' Build an array of matches:
dim search_strings as c = comma_to_crlf("oranges,apples,pears,bananas")
dim string as c = "This string contains apples, pears, and oranges, but no other fruits."
dim occurrence as N = 1

dim pos as N = *at_multi(search_strings,string,occurrence)
dim posArr[0] as N
while (pos > 0)
    posArr.push(pos)
    occurrence = occurrence + 1
    pos = *at_multi(search_strings,string,occurrence)
end while

? posArr.dump()
= 22
30
41

See Also