stringlib::contains -- test for
substring
IntroductionWith stringlib::contains a string can be tested whether
it contains another string.
Call(s)stringlib::contains(string1, string2 <,
option>)
Parametersstring1, string2 |
- | non empty string |
OptionsIndex |
- | causes the first index position at which
string2 appears in string1 to be returned.
The return value is 0 if string2 occurs
nowhere in string1. |
IndexList |
- | causes the list of all positions at which
string2 appears in string1 to be returned.
The returned list may be empty. |
ReturnsTRUE, if string1 contains
string2, otherwise FALSE. An integer (or a
list of integers) that determines the position, if an option is
given.
Related
Functions
Detailsstring2 is not detected if overlapped
by the tail of a previously detected occurrence. See Example 2.
Example
1If called without options,
stringlib::contains simply returns TRUE or
FALSE.
>> stringlib::contains("abcdeabcdeabcde", "bc")
TRUE
>> stringlib::contains("abcdeabcdeabcde", "bc", Index)
1
>> stringlib::contains("abcdeabcdeabcde", "bc", IndexList)
[1, 6, 11]
Example
2The following call does not return
[0,1] because the first matching substring has not ended
when the second begins.
>> stringlib::contains("aaa", "aa", IndexList)
[0]
string::contains