Next: , Previous: , Up: Basic Editing   [Contents][Index]


3.19 From Strings to Characters

Despite being atomic values, poke strings can be indexed in order to retrieve individual characters:

(poke) "word"[2]
0x72UB

Note how the indexing is zero-based, i.e. the first position in the string is referred as [0], the second position with [1], and so on.

If you specify a negative index, or an index that is too big, you will get an error:

(poke) "word"[-1]
<stdin>:1:8: error: index is out of bounds of string
"word"[-1];
       ^
(poke) "word"[5]
<stdin>:1:8: error: index is out of bounds of string
"word"[5];
       ^