strlength(str)
ans = 12
count(str,"")
ans = 13
Replace a substring with the empty string. When you call replace with an empty string, it removes
the substring and replaces it with a string that has zero characters.
replace(str,"world","")
ans =
"Hello, "
Insert a substring after empty strings using the insertAfter function. Because there are empty
strings between each pair of characters, insertAfter inserts substrings between each pair.
insertAfter(str,"","-")
ans =
"-H-e-l-l-o-,- -w-o-r-l-d-"
In general, string functions that replace, erase, extract, or insert substrings allow you to specify
empty strings as the starts and ends of the substrings to modify. When you do so, these functions
operate on the start and end of the string, and between every pair of characters.
Test for Missing Values
You can test a string array for missing values using the ismissing function. The missing string is the
string equivalent to NaN for numeric arrays. It indicates where a string array has missing values. The
missing string displays as.
To create a missing string, convert a missing value using the string function.
str = string(missing)
str =
You can create a string array with both empty and missing strings. Use the ismissing function to
determine which elements are strings with missing values. Note that the empty string is not a
missing string.
str(1) = "";
str(2) = "Gemini";
str(3) = string(missing)
str = 1x3 string
""
"Gemini"
ismissing(str)
ans = 1x3 logical array
0
0
1
6 Characters and Strings
6-22
ans = 12
count(str,"")
ans = 13
Replace a substring with the empty string. When you call replace with an empty string, it removes
the substring and replaces it with a string that has zero characters.
replace(str,"world","")
ans =
"Hello, "
Insert a substring after empty strings using the insertAfter function. Because there are empty
strings between each pair of characters, insertAfter inserts substrings between each pair.
insertAfter(str,"","-")
ans =
"-H-e-l-l-o-,- -w-o-r-l-d-"
In general, string functions that replace, erase, extract, or insert substrings allow you to specify
empty strings as the starts and ends of the substrings to modify. When you do so, these functions
operate on the start and end of the string, and between every pair of characters.
Test for Missing Values
You can test a string array for missing values using the ismissing function. The missing string is the
string equivalent to NaN for numeric arrays. It indicates where a string array has missing values. The
missing string displays as
To create a missing string, convert a missing value using the string function.
str = string(missing)
str =
You can create a string array with both empty and missing strings. Use the ismissing function to
determine which elements are strings with missing values. Note that the empty string is not a
missing string.
str(1) = "";
str(2) = "Gemini";
str(3) = string(missing)
str = 1x3 string
""
"Gemini"
ismissing(str)
ans = 1x3 logical array
0
0
1
6 Characters and Strings
6-22
