string.split
string: newstr = split (str)
string: newstr = split (str, delimiter)
string: newstr = split (str, delimiter, dim)
string: [newstr, match] = split (…)
Split string array at delimiters.
newstr = split (str) divides each element of str
at whitespace characters and returns the pieces as a string array. The
whitespace characters are the space, tab, newline, carriage return, form
feed, and vertical tab.
newstr = split (str, delimiter) divides each
element at the substrings specified by delimiter, which can be a
string array, a character vector, or a cell array of character vectors.
When delimiter contains several substrings they are all used; at a
given position the substrings are tried in order and the first that
matches is taken. Delimiters are not collapsed, so consecutive
delimiters yield empty strings in newstr.
The pieces of each element are laid out along a new dimension. For a
string scalar that splits into n pieces, newstr is
nx1; for an Mx1 column it is Mxn; for a
1xM row it is 1xMxn; and in general the pieces extend
the first trailing singleton dimension. Every element of str must
split into the same number of pieces. Missing values in str are
preserved and count as a single piece.
newstr = split (str, delimiter, dim) lays
the pieces out along dimension dim, which must be a dimension along
which str has size 1.
[newstr, match] = split (…) also returns the
delimiters matched between the pieces. match has the same layout
as newstr but with one fewer element along the split dimension.
Source Code: string
split breaks a string at each occurrence of a delimiter — the inverse of join.
s = string ('2024-01-15')
s = string "2024-01-15"
split (s, '-')
ans =
3x1 string array
"2024"
"01"
"15"