Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

stringlib::contains

Test for substring

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

Syntax

stringlib::contains(string1, string2, options)

Description

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

Examples

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)

Parameters

string1, string2

Non empty string

Options

Index

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.

IndexList

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?