Categories &

Functions List

Class Definition: string

Class: string

Array representing sequences of characters.

A string array is an array, where each element stores a sequence of characters of arbitraty length.

A string array can also have missing elements, which differ from a sequence of characters of zero length (the equivalent of an empty character vector).

To enable existing functions to handle string arrays as if they were cell arrays of character vectors or character arrays, use the convertCharsToStrings function inside your code. To enable functions working with string arrays to accept cell arrays of character vectors or character vectors as if they were string arrays or string scalars, use the convertStringsToChars function.

See also: convertCharsToStrings, convertStringsToChars

Source Code: string

Methods

string: str = string ()
string: str = string (in)
string: str = string (calendarDuration, 'Format', FMT)
string: str = string (duration, 'Format', FMT)
string: str = string ({in1, …, inN})

Create a new string array.

str = string () creates a scalar string array, whose element contains an empty character vector.

str = string (in) creates a string array of the same size as in, which is converted to string according to the following options:

  • character arrays and cell arrays of character vectors are converted via the core cellstr function.
  • numeric arrays are converted via the code num2str function.
  • logical arrays are converted to either false or true character sequences.
  • categorical arrays are converted via their cellstr method.
  • datetime arrays are converted via their dispstrings method.
  • calendarDuration arrays and duration arrays are converted via their respective cellstr methods, in which case an extra pair argument is supported to allow parsing to the respective method the appropriate display format. See calendarDuration and duration for valid formats parsed through FMT to each class method. Extra input arguments to the string constructor except for this case are ignored.
  • missing arrays are converted to a string array of missing elements.

str = string ({in1, …, inN}) creates a string array from a cell array, which may contain any combination of the aforementioned data types, provided that each cell element is compatible to a string scalar. When using this syntax, calendarDuration arrays and duration arrays are converted via their dispstrings method, hence no extra format argument is meaningful.

See also: calendarDuration, categorical, datetime, duration, missing

string: cstr = cellstr (str)

Convert string array to a cell array of character vectors.

cstr = cellstr (str) returns a cell array of character vectors, cstr, which has the same size as the input string str. Both empty strings and missing values are returned as empty character vectors.

string: c_arr = cell (str)

Convert string array to a cell array.

c_arr = cell (str) returns a cell array, c_arr, which has the same size as the input string str. All strings are converted to character vectors. Empty strings are converted to '' empty character vectors, while missing values are returned as [] empty numeric vectors.

string: c_mat = char (str)

Convert string array to a character matrix.

c_mat = char (str) returns a character matrix, c_mat, which contains as many rows as the elements of the string. Both empty strings and missing values are returned as empty character vectors.

string: X = double (str)

Convert string array to a double array.

X = char (str) returns a double array, X, which has the same size as the input string str. All elements in str that represent real or complex numbers are converted to equivalent double values. Otherwise, NaN is returned.

string: sz = size (str)
string: dim_sz = size (str, dim)
string: dim_sz = size (str, d1, d2, …)
string: [rows, columns, …, dim_n_sz] = size (…)

Return the size of a string array.

sz = size (str) returns a row vector with the size (number of elements) of each dimension for the string array str.

dim_sz = size (str, dim) returns the size of the corresponding dimension specified in dim. If dim is a vector, then dim_sz is a vector of the same length and with each element corresponding to a specified dimension. Multiple dimensions may also be specified as separate arguments.

With a single output argument, size returns a row vector. When called with multiple output arguments, size returns the size of dimension N in the Nth argument.

string: out = ndims (str)

Number of dimensions in a string array.

out = ndims (str) returns the number of dimensions of the string array D.

string: out = numel (str)

Total number of elements in a string array.

string: out = strlength (str)

Length of text in string arrays.

string: TF = iscolumn (str)

Test if string array is a column vector.

TF is true, if string array str is a column vector.

string: TF = isempty (str)

Test if string array is empty.

TF is true, if string array str is empty.

string: TF = ismatrix (str)

Test if string array is a matrix.

TF is true, if string array str is a matrix.

string: TF = ismember (str1, str2)

Test for set member in string arrays.

TF is a logical array of the same size as str1.

string: TF = ismissing (str)

Test for missing elements in string array.

TF is a logical array of the same size as str.

string: TF = isrow (str)

Test if string array is a row vector.

TF is true, if string array str is a row vector.

string: TF = isscalar (str)

Test if string array is a scalar.

TF is true, if string array str is a scalar.

string: TF = isvector (str)

Test if string array is a vector.

TF is true, if string array str is a vector.

string.eq is not documented.
string.ge is not documented.
string.gt is not documented.
string.le is not documented.
string.lt is not documented.
string.ne is not documented.
string.append is not documented.
string.compose is not documented.
string: newstr = erase (str, pat)

Remove content from string array.

newstr = erase (str, pat) removes the occurences of pat from each element of the string array str. newstr is a string array of the same size as str.

string.eraseBetween is not documented.
string.extract is not documented.
string.extractAfter is not documented.
string.extractBefore is not documented.
string.extractBetween is not documented.
string.insertAfter is not documented.
string.insertBefore is not documented.
string.replace is not documented.
string.replaceBetween is not documented.
string: newstr = reverse (str)

Reverse order of characters in string array.

newstr = reverse (str) reverses the order of the characters in every each element of the string array str. newstr is a string array of the same size as str.

string.sort is not documented.
string.split is not documented.
string: newstr = strcat (str1, str2), …)

Horizontal concatenation of texts in string array.

newstr = strcat (str1, str2, …) merges horizontally all the input arguments into a string array, as long as any of the input arguments is a string array. All inputs must be of common size or scalars. All inputs must be character vectors, cell arrays of character vectors, or string arrays.

string.strip is not documented.
string.pad is not documented.
string.join is not documented.
string.plus is not documented.
string: newstr = lower (str)

Convert contents of strinf array to lower case.

newstr = lower (str) converts all upper case characters in every element of the string array str to lower case. newstr is a string array of the same size as str.

string: newstr = upper (str)

Convert contents of strinf array to upper case.

newstr = upper (str) converts all lower case characters in every element of the string array str to upper case. newstr is a string array of the same size as str.