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.


Split a string

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.


stringlib::split(string, <separator>)


stringlib::split(string, separator) splits string in all parts separated by the string given as separator, that is not included in the returned strings.

If no separator is given, a single space is used as separator.

A returned part can be the empty string.

When the given string does not contain the separator, a list with the unchanged string is returned.


Example 1

The given string is splitted into the numbers separated by comma:

stringlib::split("1,2,3,4,5", ",")

In the next example is the separator a comma followed by a space:

stringlib::split("1, 2, 3, 4, 5", ", ")

Without separator a single space is used as separator:

stringlib::split("1, 2, 3, 4, 5")

Example 2

The parts can be empty strings – five empty strings separated by four single spaces:

stringlib::split("    ", " ")

The following string (five spaces) consists of two empty strings and a single space separated by two double spaces:

stringlib::split("     ", "  ")

Example 3

When the string does not contain the separator, a list with the unchanged string is returned:

stringlib::split("1,2,3,4,5", ".")


string, separator

Any non-empty MuPAD® string

Return Values

List of all parts of string without all parts separator; the string itself, if string does not contain separator.

Was this topic helpful?