The following functions are useful when working with strings:
concat(S1, S2, S3, ...) Returns the string formed by concatenating
strings S1, S2, and so
on.
substr(S, m, n) Returns the substring of S having
n characters starting at position m.
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.
strlen(S) Returns the integer number of characters in
S.
num2str(z) Converts a scalar z
into a string.
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.
str2num(Sn) Converts a string of numbers Sn
into a constant.
str2vec(S) Converts a string S to
a vector of ANSI codes.
vec2str(v) Converts a vector of integer ANSI codes to
a string.
IsString(x) Returns 1 if x is
a string, otherwise returns 0. This function is most useful inside the conditional
statement of a program.
error(S) Returns the string S
as an error message. Typically used in a program. S may contain the characters \n,
which cause the resulting error message to wrap to a new line.
Arguments:
S, S1, S2, S3, SubS... are strings.
Sn is a string representing a number. The number
may be complex, in engineering notation, or in decimal, binary, octal, or
hexadecimal format, using Mathcad's conventions for expressing
numbers. For example, the number 255 may be represented by the string
0FFh, using a leading 0 to distinguish the "FF"
as digits.
Sf (optional for one-variable case) is a string
containing control codes to specify location of the formatted argument(s)
in the output. Each argument is referenced as {#},
starting with 0. For example, format("The date is
{0}/{1}/{2}", m, d, y).
x, x1, x2, x3, ... are any valid mathcad expressions,
including scalars, arrays, and so on.
m and n are non-negative
integers.
z is a scalar.
v is a vector of integers representing ANSI code points
for any valid string character. Acceptable values are integers in the range
9, 10, 13, or 32 - 255. You may find it convenient to enter these in hexadecimal
format.
Notes:
The position of the first character in a string is zero, unless you decide
to associate string indexing
with the array ORIGIN for the worksheet. For example, in the string "yes"
the letter "y" is the 0th character.
The str2num function could be used along with an import of hex, octal,
or binary data as strings. Append the appropriate suffix using concat,
and convert the numbers to their decimal values for further processing in
Mathcad.
You can use the format function in place of concat when you
need to make a string out of multiple values of different types. This function
is used internally to create the output for the debugging
functions.
The mapping of ANSI codes to characters is done by your system codepage,
and depends on the language of your operating system. It is possible
for the same document to produce different strings/codes depending on the
currently installed codepage of the system on which it is run.