Functions > Utility Functions > String Functions
String Functions
Returning Strings
num2str(z)—Converts a scalar z into a string.
vec2str(v)—Converts a vector of UNICODE codes in v to a string. This function also works with zero-length strings, such as vec2str(0) = "".
concat("S1", "S2", "S3", ...)—Returns the string formed by concatenating strings S1, S2, S3, ... .
substr("S", m, n)—Returns the substring of S having n characters starting at position m.
format("Sf", x1, x2, x3, ...)—Returns a string containing the value of the arguments x1, x2, x3,... with print order and surrounding text specified by Sf. Each argument is referenced as {#}, starting with 0:
format("The date is {0}/{1}/{2}", m, d, y)
You can use the format function in place of concat when you need to make a string out of multiple values of different types.
error("S")—Returns string S as an error message. This function is used primarily with programs. You can use the error function in conjunction with the if function.
The error function does not support the new-line command /n inside user-defined error messages.
Working with Strings
str2num("Sn")—Converts a string Sn into a constant.
str2vec("S")—Converts a string S to a vector of UNICODE codes corresponding to the characters in S. This function also works with zero-length strings, such as str2vec("") = 0
strlen("S")—Returns the integer number of characters in S.
search("S", "SubS", m)—Returns the starting position of the substring SubS in S, beginning from position m in S. If the substring is not found after the specified starting position, it returns either −1 or ORIGIN − 1, depending on whether strings are indexed to ORIGIN or not.