4
Any group of characters beginning with an
5
alphabetic or numeric character is a string,
6
unless it belongs to one of the groups below
7
(such as an Integer or Time).
13
test: String characters
15
A string can contain any alphabetic or
16
numeric character, along with many
17
punctuation characters, including the
18
period, dash, space, quotes, exclamation, and
22
- It's for writing data structures in plain text.
24
- And what? That's not good enough for you?
25
- No, I mean, "And what about Yaml?"
26
- Oh, oh yeah. Uh.. Yaml for Ruby.
30
"It's for writing data structures in plain text.",
32
"And what? That's not good enough for you?",
33
"No, I mean, \"And what about Yaml?\"",
34
"Oh, oh yeah. Uh.. Yaml for Ruby."
37
test: Indicators in Strings
39
Be careful using indicators in strings. In particular,
40
the comma, colon, and pound sign must be used carefully.
42
the colon followed by space is an indicator: but is a string:right here
43
same for the pound sign: here we have it#in a string
44
the comma can, honestly, be used in most cases: [ but not in, inline collections ]
47
'the colon followed by space is an indicator' => 'but is a string:right here',
48
'same for the pound sign' => 'here we have it#in a string',
49
'the comma can, honestly, be used in most cases' => array('but not in', 'inline collections')
54
Any YAML type can be forced into a string using the
57
date string: !str 2001-08-01
58
number string: !str 192
61
'date string' => '2001-08-01',
62
'number string' => '192'
65
test: Single-quoted Strings
67
You can also enclose your strings within single quotes,
68
which allows use of slashes, colons, and other indicators
69
freely. Inside single quotes, you can represent a single
70
quote in your string by using two single quotes next to
73
all my favorite symbols: '#:!/%.)'
75
why do i hate them?: 'it''s very hard to explain'
76
entities: '£ me'
79
'all my favorite symbols' => '#:!/%.)',
80
'a few i hate' => '&(*',
81
'why do i hate them?' => 'it\'s very hard to explain',
82
'entities' => '£ me'
85
test: Double-quoted Strings
87
Enclosing strings in double quotes allows you
88
to use escapings to represent ASCII and
91
i know where i want my line breaks: "one here\nand another here\n"
94
'i know where i want my line breaks' => "one here\nand another here\n"
97
test: Multi-line Quoted Strings
100
Both single- and double-quoted strings may be
101
carried on to new lines in your YAML document.
102
They must be indented a step and indentation
103
is interpreted as a single space.
105
i want a long string: "so i'm going to
106
let it go on and on to other lines
107
until i end it with a quote."
109
array('i want a long string' => "so i'm going to ".
110
"let it go on and on to other lines ".
111
"until i end it with a quote."
118
Unquoted strings may also span multiple lines, if they
119
are free of YAML space indicators and indented.
121
- My little toe is broken in two places;
122
- I'm crazy to have skied this way;
123
- I'm not the craziest he's seen, since there was always the German guy
124
who skied for 3 hours on a broken shin bone (just below the kneecap);
125
- Nevertheless, second place is respectable, and he doesn't
126
recommend going for the record;
127
- He's going to put my foot in plaster for a month;
128
- This would impair my skiing ability somewhat for the
129
duration, as can be imagined.
132
"My little toe is broken in two places;",
133
"I'm crazy to have skied this way;",
134
"I'm not the craziest he's seen, since there was always ".
135
"the German guy who skied for 3 hours on a broken shin ".
136
"bone (just below the kneecap);",
137
"Nevertheless, second place is respectable, and he doesn't ".
138
"recommend going for the record;",
139
"He's going to put my foot in plaster for a month;",
140
"This would impair my skiing ability somewhat for the duration, ".
141
"as can be imagined."
146
You can use the tilde '~' character for a null value.
149
hosted by: Bob and David
150
date of next season: ~
153
'name' => 'Mr. Show',
154
'hosted by' => 'Bob and David',
155
'date of next season' => null
160
You can use 'true' and 'false' for Boolean values.
163
Do I rely on Gus for Sustenance?: false
166
'Is Gus a Liar?' => true,
167
'Do I rely on Gus for Sustenance?' => false
173
An integer is a series of numbers, optionally
174
starting with a positive or negative sign. Integers
175
may also contain commas for readability.
180
negative one-thousand: -1,000
185
'one-thousand' => 1000,
186
'negative one-thousand' => -1000
189
test: Integers as Map Keys
191
An integer can be used a dictionary key.
206
Floats are represented by numbers with decimals,
207
allowing for scientific notation, as well as
208
positive and negative infinity and "not a number."
211
larger float: 1,000.09
212
scientific notation: 1.00009e+3
215
'a simple float' => 2.0,
216
'larger float' => 1000.09,
217
'scientific notation' => 1000.09
223
You can represent timestamps by using
224
ISO8601 format, or a variation which
225
allows spaces between the date, time and
228
iso8601: 2001-12-14t21:59:43.10-05:00
229
space separated: 2001-12-14 21:59:43.10 -05:00
232
'iso8601' => mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" ),
233
'space separated' => mktime( 2001, 12, 14, 21, 59, 43, 0.10, "-05:00" )
239
A date can be represented by its year,
240
month and day in ISO8601 order.