Categories &

Functions List

Class Definition: string

datatypes: string

Array representing sequences of characters.

A string array is an array, where each element stores a sequence of characters of arbitrary 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})

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)

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)

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)

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)

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 (…)

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)

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

string: out = numel (str)

string: out = strlength (str)

string: N = length (str)

N = length (str) returns the size of the longest dimension of the string array str, unless any of its dimensions has zero length, in which case length (D) returns 0.

string: hey = keyHash (str)

h = keyHash (str) generates a uint64 scalar that represents the input array str. keyHash utilizes the 64-bit FMV-1a variant of the Fowler-Noll-Vo non-cryptographic hash function.

h = keyHash (str), base also generates a 64-bit hash code using base as the offset basis for the FNV-1a hash algorithm. base must be a uint64 integer type scalar. Use this syntax to cascade keyHash on multiple objects for which a single hash code is required.

Note that unlike MATLAB, this implementation does no use any random seed. As a result, keyHash will always generate the exact same hash key for any particular input across different workers and Octave sessions.

string: TF = iscolumn (str)

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

string: TF = isempty (str)

TF is true, if string array str is empty.

string: TF = ismatrix (str)

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

string: TF = ismember (str1, str2)

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

string: TF = ismissing (str)

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

string: TF = isrow (str)

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

string: TF = isscalar (str)

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

string: TF = isvector (str)

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

string: TF = eq (A, B)

TF is true, if string A is lexicographically equal to B. If one input is a string array, the other input can be a string array, a character vector, or a cell array of character vectors. This is equivalent to the strcmp function.

string: TF = eq (A, B)

TF is true, if string A is lexicographically greater than or equal to B. If one input is a string array, the other input can be a string array, a character vector, or a cell array of character vectors.

string: TF = eq (A, B)

TF is true, if string A is lexicographically greater than B. If one input is a string array, the other input can be a string array, a character vector, or a cell array of character vectors.

string: TF = eq (A, B)

TF is true, if string A is lexicographically less than or equal to B. If one input is a string array, the other input can be a string array, a character vector, or a cell array of character vectors.

string: TF = eq (A, B)

TF is true, if string A is lexicographically less than B. If one input is a string array, the other input can be a string array, a character vector, or a cell array of character vectors.

string: TF = ne (A, B)

TF is true, if string A is lexicographically not equal to B. If one input is a string array, the other input can be a string array, a character vector, or a cell array of character vectors. TF = ne (A, B) is equivalent to TF = ! strcmp (A, B).

string: TF = strcmp (A, B)

TF is true, if string A is lexicographically equal to B. If one input is a string array, the other input can be a string array, a character vector, or a cell array of character vectors.

If either A or B is a string array or a cell array of character vectors, then a logical array TF of the same size is returned, containing the values described above for every member of the array. In this case, the other argument may also be a string array or a cell array of character vectors (of the same size or scalar), or a character vector.

string: TF = strcmp (A, B)

TF is true, if string A is lexicographically equal to B, disregarding case of alphabetic characters. If one input is a string array, the other input can be a string array, a character vector, or a cell array of character vectors.

If either A or B is a string array or a cell array of character vectors, then a logical array TF of the same size is returned, containing the values described above for every member of the array. In this case, the other argument may also be a string array or a cell array of character vectors (of the same size or scalar), or a character vector.

string: TF = strncmp (A, B, n)

TF is true, if the first n characters of strings A and B are lexicographically equal. If one input is a string array, the other input can be a string array, a character vector, or a cell array of character vectors.

If either A or B is a string array or a cell array of character vectors, then a logical array TF of the same size is returned, containing the values described above for every member of the array. In this case, the other argument may also be a string array or a cell array of character vectors (of the same size or scalar), or a character vector.

string: TF = strncmp (A, B, n)

TF is true, if the first n characters of strings A and B are lexicographically equal, disregarding case of alphabetic characters. If one input is a string array, the other input can be a string array, a character vector, or a cell array of character vectors.

If either A or B is a string array or a cell array of character vectors, then a logical array TF of the same size is returned, containing the values described above for every member of the array. In this case, the other argument may also be a string array or a cell array of character vectors (of the same size or scalar), or a character vector.

string: newstr = append (str1, …, strN)

newstr = append (str1, …, strN) combines the text from each input argument, str1, …, strN), which must be either string arrays, cell arrays of character vectors, or character vectors or matrices. All input arguments must be of compatible sizes. Character vectors are treated as a single text element and character matrices are treated as a column of elements. apped preserves any trailing white spaces, unlike the strcat function.

string: newstr = erase (str, pat)

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: newstr = reverse (str)

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: newstr = strcat (str1, str2, …)

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: newstr = plys (str1, str2)

newstr = lower (str) is the equivalent of the syntax newstr = str1 + str2 and appends str2 to str1. Both input arguments must be string arrays of compatible size.

string: newstr = lower (str)

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)

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.

string: B = unique (A)
string: B = unique (A, 'rows')
string: [B, ixA, ixB] = unique (…)
string: … = unique (…, order)
string: … = unique (…, occurence)

B = unique (A) returns the unique values of the string array A in the string vector B sorted lexicographically. If If A is a column vector, then B is also a column vector, otherwise unique returns a row vector.

B = unique (A, 'rows') returns the unique rows of the string matrix A in the string matrix B sorted in lexicographical order.

[B, ixA, ixB] = unique (…) also returns index vectors ixA and ixB such that B = A(ixA) and A = B(ixB), unless the 'rows' optional argument is given, in which case B = A(ixA,:) and A = B(ixB,:).

… = unique (…, order) also specifies the order of the returned unique values. order may be either 'sorted', which is the default behavior, or 'stable', in which case the unique values are returned in order of appearance.

… = unique (…, occurence) also specifies the which index is returned in ixA, where there are repeated values or rows (if opted) in the input categorical array. occurence may be either 'first', which is the default and returns the index of the first occurence of each unique value, or 'last', in which case the last occurence of each unique value is returned.

string: C = cat (dim, A, B, …)

C = cat (dim, A, B, …) concatenates string arrays A, B, … along dimension dim. All input arrays must have the same size except along the operating dimension dim. Any of the input arrays may also be character matrixes, cell arrays of character vectors, numeric arrays, or logical arrays of compatible size.

string: C = horzcat (A, B, …)

C = horzcat (A, B, … is the equivalent of the syntax B = [A, B, …] and horizontally concatenates the string arrays A, B, …. All input arrays must have the same size except along the second dimension. Any of the input arrays may also be character matrixes, cell arrays of character vectors, numeric arrays, or logical arrays of compatible size.

string: C = vertcat (A, B, …)

C = vertcat (A, B, … is the equivalent of the syntax B = [A; B; …] and vertically concatenates the string arrays A, B, …. All input arrays must have the same size except along the second dimension. Any of the input arrays may also be character matrixes, cell arrays of character vectors, numeric arrays, or logical arrays of compatible size.

string: B = repmat (A, n)
string: B = repmat (A, d1, …, dN)
string: B = repmat (A, dimvec)

B = repmat (A, n) returns a string array B containing n copies of the input string array A along every dimension of A.

B = repmat (A, d1, …, dN) returns an array B containing copies of A along the dimensions specified by the list of scalar integer values d1, …, dN, which specify how many copies of A are made in each dimension.

B = repmat (A, dimvec) is equivalent to the previous syntax with dimvec = [d1, …, dN].

string: B = repelem (A, n)
string: B = repelem (A, d1, …, dN)

B = repelem (A, n) returns a string vector B containing repeated elements of the input A, which must be a string vector. If n is a scalar, each element of A is repeated n times along the non-singleton dimension of A. If n is a vector, it must have the same elemnts as A, in which case it specifies the number of times to repeat each corresponding element of A.

B = repelem (A, d1, …, dN returns an array B with each element of A repeated according to the the list of input arguments d1, …, dN each corresponding to a different dimension 1:ndims (A) of the input array A. d1, …, dN must be either scalars or vectors with the same length as the corresponding dimension of A containing non-negative integer values specifying the number of repetitions of each element along the corresponding dimension.

string: B = repelems (A, R)

B = repelems (A, R) returns a string vector B containing repeated elements of the input A, which must be a string vector. R must be a 2×N matrix of integers. Entries in the first row of R correspond to the linear indexing of the elements in A to be repeated. The corresponding entries in the second row of R specify the repeat count of each element.

string: B = reshape (A, d1, …, dN)
string: B = reshape (A, …, [], …)
string: B = reshape (A, dimvec)

B = reshape (A, d1, …, dN) returns a string array B with specified dimensions d1, …, dN, whose elements are taken columnwise from the string array A. The product of d1, …, dN must equal the total number of elements in A.

B = reshape (A, …, [], …) returns a string array B with one dimension unspecified which is calculated automatically so that the product of dimensions in B matches the total elements in A, which must be divisible the product of specified dimensions. An empty matrix ([]) is used to flag the unspecified dimension.

string: B = circshift (A, n)
string: B = circshift (A, n, dim)

B = circshift (A, n) circularly shifts the elements of the string array A according to n. If n is a nonzero integer scalar, then the elements of A are shifted by n elements along the first non-singleton dimension of A. If n is a vector, it must not be longer that the number of dimensions of A with each value of n corresponding to a dimension in A. The sign of the value(s) in n specify the direction in the elements of A are shifted.

B = circshift (A, n, dim) circularly shifts the elements of the string array A along the dimension specified by dim. In this case, n must be a scalar integer value.

string: B = permute (A, dims)

B = permute (A, dims) returns the generalized transpose of the string array A by rearranging its dimensions according to the permutation vector specified in dims.

dims must index all the dimensions 1:ndims (A) of the input array A, in any order, but only once. The Nth dimension of A gets remapped to the dimension in B specified by dims(N).

string: A = ipermute (B, dims)

A = ipermute (B, dims) returns the inverse of the generalized transpose performed by the permute function. The expression ipermute (permute (A, dims), dims) returns the original array A.

dims must index all the dimensions 1:ndims (B) of the input array B, in any order, but only once. The dimension of B specified in dims(N) gets remapped to the Nth dimension of A.

string: B = transpose (A)

B = transpose (A) is the equivalent of the syntax B = A.' and returns the transpose of the string matrix A.

string: B = ctranspose (A)

B = ctranspose (A) is the equivalent of the syntax B = A' and returns the transpose of the string matrix A. For string arrays, ctranspose is identical to transpose.