Documentation

stringlib::split

Split a string

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

stringlib::split(string, <separator>)

Description

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.

Examples

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", ".")

Parameters

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?