Test for Empty Strings and Missing Values
String arrays can contain both empty strings and missing values. Empty strings contain
zero characters and display as double quotes with nothing between them (""). You can
determine if a string is an empty string using the == operator. The empty string is a
substring of every other string. Therefore, functions such as contains always find the
empty string within other strings. String arrays also can contain missing values. Missing
values in string arrays display as <missing>. To find missing values in a string array, use
the ismissing function instead of the == operator.
Test for Empty Strings
You can test a string array for empty strings using the == operator.
Starting in R2017a, you can create an empty string using double quotes with nothing
between them (""). Note that the size of str is 1-by-1, not 0-by-0. However, str contains
zero characters.
str = ""
str =
""
Create an empty character vector using single quotes. Note that the size of chr is 0-by-0.
The character array chr actually is an empty array, and not just an array with zero
characters.
chr = ''
chr =
0x0 empty char array
Create an array of empty strings using the strings function. Each element of the array
is a string with no characters.
str2 = strings(1,3)
str2 = 1x3 string array
"" "" ""
Test if str is an empty string by comparing it to an empty string.
Test for Empty Strings and Missing Values