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::pos

Position of a 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::pos(string1, string2, <pos>)

Description

stringlib::pos returns the position of a substring in a string.

The third optional argument must be less than the length of string1.

If string1 does not contain string2, then FAIL will be returned.

Examples

Example 1

In case of several occurrences of the substring, the position of the first is returned.

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

Example 2

If a starting point for the search is given, stringlib::pos returns the first position at which the substring occurs after that starting point.

stringlib::pos("abcdeabcdeabcde", "bc", 5)

Example 3

The result is FAIL if the substring does not occur at all or after the given starting point.

stringlib::pos("abcdeabcdeabcde", "bc", 14)

Parameters

string1, string2

Non empty string

pos

Integer that determines the first position to search

Return Values

Integer that determines the position or FAIL.

See Also

MuPAD Functions

Was this topic helpful?