Test for substring

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.


stringlib::contains(string1, string2, options)


stringlib::contains(string1, string2) checks, whether string1 contains another string string2.


Example 1

If called without options, stringlib::contains simply returns TRUE or FALSE.

stringlib::contains("abcdeabcdeabcde", "bc")

stringlib::contains("abcdeabcdeabcde", "cb")

stringlib::contains("abcdeabcdeabcde", "bc", Index)

stringlib::contains("abcdeabcdeabcde", "cb", Index)

stringlib::contains("abcdeabcdeabcde", "bc", IndexList)

stringlib::contains("abcdeabcdeabcde", "cb", IndexList)

Example 2

The following call does not return [1,2] because the first matching substring has not ended when the second begins.

stringlib::contains("aaa", "aa", IndexList)


string1, string2

Non empty string



Causes the first index position at which string2 appears in string1 to be returned as integer. The return value is FALSE, if string2 occurs nowhere in string1.


Causes the list of all positions at which string2 appears in string1 to be returned. The returned list is empty if string2 occurs nowhere in string1.

An occurrence of string2 is not detected if overlapped by the tail of a previously detected occurrence. See Example 2.

Return Values

TRUE, an integer, or a list of integers that determines the position (if an option is given), when string1 contains string2, otherwise FALSE or an empty list.

See Also

MuPAD Functions

Was this topic helpful?