Text strings are used for file names and plot labels. Strings are enclosed in double quotes and can contain blanks or punctuation but they cannot contain a RETURN.
Variables can be defined or assigned as strings. If the variable is to be evaluated many times it is better to assign the string so that multiple copies of the string do not need to be created.
Numeric results can be converted to strings with the built-in function sprintf(format,n). This function is essentially the same as the C standard library function.
The format parameter is a string which controls the conversion. The format must contain a single conversion specification. Any characters that are not part of the conversion specification are copied directly to the result string. A conversion specification begins with a % character. A % character can be output by using %%.
The conversion has the following form: (brackets indicate optional values).
 %[flags][size][.precision]conversion
- | left justify |
+ | include leading plus |
space | include a leading space |
0 | pad with leading zeros |
# | use alternate form |
minimum number of output characters The field is padded with spaces if needed |
floating point | number of digits after the decimal point |
integer | minimum number of digits |
string | maximum number of characters |
character | n | output | # alternate form |
---|---|---|---|
c | ascii code | single character | |
d | integer | signed integer | |
e E | floating point | E format | always include point |
f | floating point | fixed point format | always include point |
g G | floating point | smaller of f or e | include trailing zeros |
i | integer | signed integer | |
o | integer | octal | force leading zero |
s | string | string | array of ascii codes |
u | integer | unsigned integer | |
x X | integer | hexadecimal | use 0x prefix |
format | sprintf(format,42) |
---|---|
"n=%f" | "n=42.000000" |
"n=%e" | "n=4.200000e+01" |
"n=%E" | "n=4.200000E+01" |
"n=%g" | "n=42" |
"n=%.2f" | "n=42.00" |
"n=%10.2f" | "n= 42.00" |
"n=%-10.2f" | "n=42.00 " |
"n=%d" | "n=42" |
"n=%X" | "n=2A" |
"n=%o" | "n=52" |
"n=%c" | "n=*" |
The sprintf function only allows one conversion in the format string but results can be joined together with the concatenation operator '|' . Both operands must be strings.
"what" | "not":"whatnot"
weekdays = {"mon","tues","wed","thurs","fri"}
table {weekdays}
    "mon"    "tues"    "wed"
    "thurs"    "fri"
The write() function will write out strings for the special case of a 2D array of strings and a TEXT file. Each string is written out with no quotes or separators. A line in the output file corresponds to a row in the 2D array.
An explicit index on a string will extract the ASCII value of a single character
"tues"[1]:116
-- 116 is the ASCII code for 't'
"tues"[2]:117
-- 117 is the ASCII code for 'u'
An array of character values can be packed into a string by using the
"%#s"
format with sprintf().
chars = {116,117,101,115}
sprintf("%#s",chars):"tues"
Strings are not general purpose objects. They are handled in the above special cases. Most other operations will have no effect on the string and will not generate any error messages. In cases where a string is not allowed, an undefined or an array of ASCII values is used.