### B.15 Statements for working with strings

Strings in BayES are used, primarily, to print messages on the BayES console and in directory statements. To improve the speed of evaluation of mathematical statements, which are much more frequently used, string operations and functions form a distinct part of the BayES language. This means that indexing operations or functions that work on matrices do not work on strings. However, specialized functions that operate on strings are provided and these are documented in the following table.

Note that, as with the rest of the language, strings are case sensitive: "my string" is not the same as "My String".

 Syntax Arguments and performed function x = strlength(s); x is a $1\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}1$ matrix that stores the number of characters in string s. Note that escape characters are treated as separate entries. For example, the string "∖"my string∖"" contains 13 characters, with each "∖"" occupying two places in the string. s must be a string s = strcat(s1, s2 $\left[$, s3, s4,...$\right]$); s is a string that is constructed by concatenating the strings that are passed as arguments to strcat(). s1, s2, s3, s4, $\dots$ must all be strings s = substr(r, l:u); s is a string that is constructed by extrancting the characters in r located from position l to u (margins included). Note that escape characters in s occupy two places in a string. r must be a string u and l must be positive integers with l $\le$ u strreplace(s, r, t); strreplace(s, r, l:u); The strreplace() function in the ﬁrst form replaces all occurrences in string s of the characters in string r with the characters in string t. For example, the statement strreplace(s, "∖∖", "/"); replaces all backslashes in s with forward slashes. In the second form the function replaces the characters in string s from position l to u (margins included) with the characters in string r. s, r and t must all be strings u and l must be positive integers with l $\le$ u x = strﬁnd(s, r); x is a $1\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}1$ matrix that stores the location in string s at which the ﬁrst match occurs between the characters in s and r. For example, if s is "Hello World" and r is "World", then x will be equal to seven. strﬁnd() returns 0 if s does not contain r. s must be a string r must be a string x = strﬁndr(s, r); x is a $1\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}1$ matrix that stores the location in string s at which the last match occurs between the characters in s and r. For example, if s is "Hello World" and r is "World", then x will be equal to seven. strﬁnd() returns 0 if s does not contain r. s must be a string r must be a string strcmp(s, r) The strcmp() function compares strings s and r and evaluates to true if the two strings match exactly and false otherwise. Note that the code provided in the left is not a complete statement. strcmp(s, r) would typically be the condition in an if-else or a while statement. s must be a string r must be a string s = mat2str(A $\left[$, p$\right]$); The mat2str() function produces a string s from the contents of a $1\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}1$ matrix A, using up to p digits. If p is not provided then s will contain the value of A as it appears on the BayES console after a print(A); statement. A must be a $1×1$ matrix p must be a positive integer