Mirror of the Rel4tion website/wiki source, view at <http://rel4tion.org>

[[ 🗃 ^yEzqv rel4tion-wiki ]] :: [📥 Inbox] [📤 Outbox] [🐤 Followers] [🤝 Collaborators] [🛠 Commits]

Clone

HTTPS: git clone https://vervis.peers.community/repos/yEzqv

SSH: git clone USERNAME@vervis.peers.community:yEzqv

Branches

Tags

master :: projects / idan / manual / 02-literals /

05-strings.mdwn

[[!meta title=“2.5 | Strings”]]

Strings

A string value is a sequence of zero or more characters. There are two forms for writing strings: between double quotes (") or between triples of double quotes ("""). It’s also possible to write several strings (form doesn’t matter) sequentially and they will be concatenated into a single string value. For example: "abc", """abc""" and "a" """b""" "c" are the same three-letter string value “abc”.

Between the quotes there is a sequence of characters and escape sequences. See the section about the sequences for full lists. Both numeric and symblic sequences are allowed.

Any Graphical character is allowed between the double quotes, except for \ and ", which must be escaped. Between """s, \ and """ aren’t allowed. """ can be escaped as \""". One or two consecutive "s can be written as-is without escaping. But instead of the limitation to Graphial characters, """-quoted strings allow any Unicode character except for \ and the """ sequence to be writte as-is.

"""-quoted strings are therefore good for text which has many " characters (such as dialogs in books), and as a [[!wikipedia “here document”]].

There’s the \& escape, which isn’t available to character literals. This sequence doesn’t translate into any characters, i.e. empty string. "hello" and "he\&llo" are exactly the same string value. It exists for breaking sequences. For example, there's the two-character string composed of the numeric sequence\123followed by the digit4. There's another, single-character string, which contains just the sequence\1234. To which of these values does the literal“\1234”refer? Answer: Sequences are as long as they can be, i.e. the4is parsed as part of the sequence. It can be separated from it by using&like this:“\123&4”. Another way to separate sequences is splitting the string literal, e.g.“\123” “4”`.

String examples:

"hello world"

"They said \"Hello world\""

"line 1\nline 2\nline 3"

"""This is line 1.
This is line 2.
  - Item 1
  - Item 2
  - Item 3
h
 e
  l
   l
    o"""

Examples for string literal concatenation:

"hello " "world"

"Line 1. "
"Still the same line.\n"
"Line 2."

"h" "e" "l" "l" "l" "\n"
"w" "o" "r" "l" "d" "\n"

"x\n" "y\n" "z\n"
[See repo JSON]