[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12.2.2.2 Character Strings

String is an arbitrary string of characters. Any input token consisting of letters of Latin alphabet, decimal digits, underscores dashes and dots and starting with a Latin alphabet letter or underscores is considered a string. To input strings containing other letters, surround them by double quotes. The following are valid strings:

 
A-string
"String, containing white space"

The double quote character ‘"’ must be preceeded by a backslash ‘\’ if it is part of a string:

 
"Always quote \" character"

Generally speaking, ‘\’ is an escape character, that alters the meaning of the immediately following character. If it is located at the end of the line, it allows to input newline character to strings:

 
"This string contains a \
newline character."

Other special escape sequences are:

\a

Audible bell character (ASCII 7)

\b

Backspace (ASCII 8)

\e

Escape character (ASCII 27)

\f

Form feed (ASCII 12)

\n

Newline (ASCII 10)

\r

Carriage return (ASCII 13)

\t

Horizontal tab (ASCII 9)

\\

Backslash

\ooo

(‘o’ represents an octal digit) A character whose ASCII value is represented by the octal number ‘ooo’.

\xHH
\XHH

(‘H’ represents a hex digit) A character whose ASCII value is represented by the hex number ‘HH’.

If the character following the backslash is not one of those specified, the backslash is ignored.

An important variant of string is a numeric string, or STRNUM for short. A numeric string is a string that can be converted to a number, for example "+2". This concept is used for type conversion between integer and string values.

Another way to represent strings is using here document syntax. Its format is as follows:

 
<<[-]delimiter
  text
delimiter

Delimiter is any word you choose to delimit the text, text represent the text of the string. If delimiter is prepended by a dash, any leading tabulation characters will be removed from text. This allows for natural indentation of ‘here document’ constructs.

The ‘here document’ construct is especially useful to represent strings containing embedded newlines, as shown in the example below:

 
print <<EOT
usage: foo [OPTIONS] [NAME...]
OPTIONS are:
  -h            Print this help list.
EOT

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Sergey Poznyakoff on December, 6 2008 using texi2html 1.78.