strsplit
Tokenizes the string s with the given delimiter delim.
Syntax
R = strsplit(s)
R = strsplit(s, delim)
R = strsplit(s, delim, 'collapsedelimiters', 'value')
Inputs
- s
- String to be split.
- delim (optional)
- Delimiter. Whitespace is the default delimiter.
- 'collapsedelimiters', value (optional)
- Name-value pair for specifying output contents. Valid options for value are true or false. The default option if value is not specified is true.
Outputs
- R
- Type: cell
Examples
Using default
delimiter:
R = strsplit('string1 string2 string3')
R =
{
[1,1] string1
[1,2] string2
[1,3] string3
}
Using a cell array of strings as a
delimiter:
R = strsplit('Split this string at the letter t', {' ', 't'})
R =
{
[1,1] Spli
[1,2] his
[1,3] s
[1,4] ring
[1,5] a
[1,6] he
[1,7] le
[1,8] er
[1,9]
}
Using a cell array of strings as a delimiter, with 'collapsedelimiters' of
value
false:
R = strsplit('Split this string at the letter t', {' ', 't'}, 'collapsedelimiters', false)
R =
{
[1,1] Spli
[1,2]
[1,3]
[1,4] his
[1,5] s
[1,6] ring
[1,7] a
[1,8]
[1,9]
[1,10] he
[1,11] le
[1,12]
[1,13] er
[1,14]
[1,15]
}