string
Obtains a textual representation of an object.
Syntax
-
string(X)
-
X
is any object
-
Description
If X
is any object, then string(X)
returns a textual representation of X
. Typically, the format is optimised for maximum precision and high compatibility with external parsers. However, if X
is an object that has no natural textual representation (e.g. a pixmap or an audio clip), string(X)
might return a textual summary instead.
In general:
-
A full stop is used as decimal separator.
-
The - (U+002D: HYPHEN-MINUS) character is used as minus sign.
-
For exponential notation,
E
is used.
Specifically:
-
Integers are presented with no formatting (e.g. digit separators):
6820411818913
-
Rational numbers are written “p/q” where each part is formatted as an integer:
52/73
-
Real numbers are written with the maximum possible number of significant digits Exponential notation might be used.
3.14159265358979324
-
Complex numbers are written “x + y⋅i” if both the real and imaginary parts are non-zero.
1.06127506190503565 + 0.666239432492515255⋅i
3.14159265358979324⋅i
-
Booleans are written as
true
orfalse
. -
Strings are represented exactly “as is”; no characters or sequences are escaped.
-
The components of a vector are separated by newlines:
4.1 2.6 5
-
The rows of a matrix are separated by newlines; the columns by tabs:
1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
-
Lists separate their elements by newlines. Each element is written in its exchange-optimised single-line form:
3.14159265358979324 "alpha↲beta" ((1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1)) (1, 0, 0)
-
Sets are written using set-builder’s notation, with each element in its exchange-optimised single-line form:
{1, 3.14159265358979324, ((1, 0, 0), (0, 1, 0), (0, 0, 1)), "alpha↲beta"}
-
Colours are written with each component in maximum precision:
rgba(1, 0.843137254901961, 0, 1)
-
Pixmaps are merely summarised:
A pixmap of size 800×600.
-
Sounds are merely summarised:
A 12.2-second 32-bit 48000 Hz 1-channel sound.
-
If
X
is an object of type binary data, then you must use the AsSingleLine function to obtain it as a string of hexadecimal bytes. Thestring
function will instead interpret the data as a Unicode string.