stringlib::contains
-- test for
substringWith stringlib::contains
a string can be tested whether
it contains another string.
stringlib::contains(string1, string2 <,
option>)
string1, string2 |
- | non empty string |
Index |
- | 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. |
TRUE
, if string1
contains
string2
, otherwise FALSE
. An integer (or a
list of integers) that determines the position, if an option is
given.
string2
is not detected if overlapped
by the tail of a previously detected occurrence. See Example 2.If 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]
The 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