Next: , Previous: , Up: Data Types [Contents][Index]


4.7 Strings

Character strings are not a special data type in the Calculator. Rather, a string is represented simply as a vector all of whose elements are integers in the Latin-1 range 0 to 255. You can enter a string at any time by pressing the " key. Quotation marks and backslashes are written ‘\"’ and ‘\\’, respectively, inside strings. Other notations introduced by backslashes are:

\a 7 \^@ 0
\b 8 \^a-z 1-26
\e 27 \^[ 27
\f 12 \^\\ 28
\n 10 \^] 29
\r 13 \^^ 30
\t 9 \^_ 31
 \^? 127

Finally, a backslash followed by three octal digits produces any character from its code.

Strings are normally displayed in vector-of-integers form. The d " (calc-display-strings) command toggles a mode in which any vectors of small integers are displayed as quoted strings instead. The display of strings containing higher character codes can be enabled by increasing the custom variable calc-string-maximum-character (see Customizing Calc).

The backslash notations shown above are also used for displaying strings. For ASCII control characters (below 32), and for the DEL character (127), Calc uses the backslash-letter combination if there is one, or otherwise uses a ‘\^’ sequence. Control characters above 127 are not translated by Calc, and will show up in backslash-octal-digits notation. The display of higher character codes will depend on your display settings and system font coverage.

The only Calc feature that uses strings is compositions; see Compositions. Strings also provide a convenient way to do conversions between ASCII characters and integers.

There is a string function which provides a different display format for strings. Basically, ‘string(s)’, where s is a vector of integers in the proper range, is displayed as the corresponding string of characters with no surrounding quotation marks or other modifications. Thus ‘string("ABC")’ (or ‘string([65 66 67])’) will look like ‘ABC’ on the stack. This happens regardless of whether d " has been used. The only way to turn it off is to use d U (unformatted language mode) which will display ‘string("ABC")’ instead.

Control characters are displayed somewhat differently by string. Characters below 32, and character 127, are shown using ‘^’ notation (same as shown above, but without the backslash). The quote and backslash characters are left alone, as are characters 128 and above.

The bstring function is just like string except that the resulting string is breakable across multiple lines if it doesn’t fit all on one line. Potential break points occur at every space character in the string.


Next: HMS Forms, Previous: Vectors and Matrices, Up: Data Types [Contents][Index]

AltStyle によって変換されたページ (->オリジナル) /