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 <missing>.
To create a missing string, convert a missing value using the string function.
str = string(missing)
str =
<missing>
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 array
"" "Gemini" <missing>
ismissing(str)
ans = 1x3 logical array
6 Characters and Strings