Conversion of a matrix to a string.
s = char(M) S = char(s1, s2, ...)
char(M) converts the elements of matrix M to characters, resulting in a string of the same size.
char(s1,s2,...) concatenates vertically the strings given as arguments to produce a string matrix. If the strings do not have the same length, blanks are added to the right.
char(65:70) ABCDEF char('ab','cde') ab cde char('abc',['de';'fg']) abc de fg
setstr, operator :, ischar, logical, double
Find a substring in a string.
pos = findstr(str, sub)
findstr(str,sub) finds occurrences of string sub in string str and returns a vector of the positions of all occurrences, or the empty vector [] if there is none. Occurrences may overlap.
findstr('ababcdbaaab','ab') 1 3 10 findstr('ababcdbaaab','ac') [] findstr('aaaaaa','aaa') 1 2 3
Test for letters.
b = isletter(s)
For each character of string s, isletter(s) is true if it is a letter and false otherwise. Letters with diacritical signs are not considered as letters.
isletter('abAB12* ') 1 1 1 1 0 0 0 0 isletter([10 20 70]) 0 0 1
Test for spaces.
b = isspace(s)
For each character of string s, isspace(s) is true if it is a space, a tabulator, a carriage return or a line feed, and false otherwise.
isspace('a\tb c\nd') 0 1 0 1 0 1 0
Test for a string object.
b = ischar(obj)
ischar(obj) is true if the object obj is a character string, false otherwise. Strings can have more than one line.
ischar('abc') 1 ischar(0) 0 ischar([]) 0 ischar('') 1 ischar(['abc';'def']) 1
isletter, isspace, isnumeric, islogical, islist, setstr, char
Convert all uppercase letters to lowercase.
s2 = lower(s1)
lower(s1) converts all the uppercase letters of string s1 to lowercase. Currently, only ASCII letters (without diacritic) are converted.
lower('abcABC123') abcabc123
Conversion of a matrix to a string.
str = setstr(M)
setstr(M) converts the elements of matrix M to characters, resulting in a string of the same size. Currently, the native character encoding is used.
setstr(65:75) ABCDEFGHIJK
String comparison.
b = strcmp(s1, s2) b = strcmp(s1, s2, n)
strcmp(s1, s2) is true if the strings s1 and s2 are equal (i.e. same length and corresponding characters are equal). strcmp(s1, s2, n) compares the strings up to the n:th character. Note that this function does not return the same result as the strcmp function of the standard C library.
strcmp('abc','abc') 1 strcmp('abc','def') 0 strcmp('abc','abd',2) 1 strcmp('abc','abc',5) 1
strcmpi, operator ===, operator ~==, operator ==, findstr
String comparison with ignoring letter case.
b = strcmpi(s1, s2) b = strcmpi(s1, s2, n)
strcmpi compares strings for equality, ignoring letter case. In every other respect, it behaves like strcmp.
strcmpi('abc','aBc') 1 strcmpi('Abc','abd',2) 1
strcmp, operator ===, operator ~==, operator ==, findstr
Convert all lowercase letters to lowercase.
s2 = upper(s1)
upper(s1) converts all the lowercase letters of string s1 to uppercase. Currently, only ASCII letters (without diacritic) are converted.
upper('abcABC123') ABCABC123