str =
0x3 empty string array
Test str using the isempty function.
isempty(str)
ans = logical
1
Test a string array for empty strings. The == operator returns a logical array that is the same size as
the string array.
str = ["Mercury","","Apollo"]
str = 1x3 string
"Mercury"
""
"Apollo"
str == ''
ans = 1x3 logical array
0
1
0
Find Empty Strings Within Other Strings
Strings always contain the empty string as a substring. In fact, the empty string is always at both the
start and the end of every string. Also, the empty string is always found between any two consecutive
characters in a string.
Create a string. Then test if it contains the empty string.
str = "Hello, world";
TF = contains(str,"")
TF = logical
1
Test if str starts with the empty string.
TF = startsWith(str,"")
TF = logical
1
Count the number of characters in str. Then count the number of empty strings in str. The count
function counts empty strings at the beginning and end of str, and between each pair of characters.
Therefore if str has N characters, it also has N+1 empty strings.
str
str =
"Hello, world"
Test for Empty Strings and Missing Values
6-21
0x3 empty string array
Test str using the isempty function.
isempty(str)
ans = logical
1
Test a string array for empty strings. The == operator returns a logical array that is the same size as
the string array.
str = ["Mercury","","Apollo"]
str = 1x3 string
"Mercury"
""
"Apollo"
str == ''
ans = 1x3 logical array
0
1
0
Find Empty Strings Within Other Strings
Strings always contain the empty string as a substring. In fact, the empty string is always at both the
start and the end of every string. Also, the empty string is always found between any two consecutive
characters in a string.
Create a string. Then test if it contains the empty string.
str = "Hello, world";
TF = contains(str,"")
TF = logical
1
Test if str starts with the empty string.
TF = startsWith(str,"")
TF = logical
1
Count the number of characters in str. Then count the number of empty strings in str. The count
function counts empty strings at the beginning and end of str, and between each pair of characters.
Therefore if str has N characters, it also has N+1 empty strings.
str
str =
"Hello, world"
Test for Empty Strings and Missing Values
6-21
