Next: , Up: 文字列型   [Contents][Index]


2.4.8.1 文字列の構文

文字列にたいする入力構文は"like this"のようにダブルクォート、任意個数の文字、もう1つのダブルクォートから構成されます。文字列内にダブルクォートを含める場合は、それの前にバックスラッシュを記述します。したがって"\""は1つのダブルクォート文字だけを含む文字列です。同様にバックスラッシュを含める場合は、"this \\ is a single embedded backslash"のように、それの前にもう1つのバックスラッシュを記述します。

Since a string is an array of characters, you can specify the string characters using the read syntax of characters, but without the leading question mark. This is useful for including in string constants characters that don’t stand for themselves. Thus, control characters can be specified as escape sequences that start with a backslash; for example, "foo\r" yields ‘foo’ followed by the carriage return character. See 基本的な文字構文, for escape sequences of other control characters. Similarly, you can use the special read syntax for control characters (see コントロール文字構文), as in "foo\^Ibar", which produces a tab character embedded within a string. You can also use the escape sequences for non-ASCII characters described in 一般的なエスケープ構文, as in "\N{LATIN SMALL LETTER A WITH GRAVE}" and "\u00e0" (however, see a caveat with non-ASCII characters in 文字列内の非ASCII文字).

文字列にたいする入力構文では、改行(newline)は特別ではありません。ダブルクォートの間に改行を記述すれば、その改行は文字列内の文字となります。しかしエスケープされた改行 — 前に‘\’をともなう改行 — は文字列の一部とはなりません。同様にエスケープされたスペース‘\  も無視されます。

"It is useful to include newlines
in documentation strings,
but the newline is \
ignored if escaped."
     ⇒ "It is useful to include newlines
in documentation strings,
but the newline is ignored if escaped."
This page has generated for branch:master, commit:762705fb24fd90db318f2e51c1e762452d26f7e2 to check Japanese translation.