document string range indexing for substring

This commit is contained in:
ruby0x1
2021-04-06 19:56:28 -07:00
parent 197c0ff4f9
commit 5e60bbf0cf

View File

@ -40,6 +40,15 @@ var hPosition = metalBand.indexOf("h")
System.print(metalBand[hPosition]) //> h
</pre>
A string can also be indexed with a [Range](range.html), which will return a
new string as a substring of the original.
<pre class="snippet">
var example = "hello wren"
System.print(example[0...5]) //> hello
System.print(example[-4..-1]) //> wren
</pre>
If you want to work with a string as a sequence numeric code points, call the
`codePoints` getter. It returns a [Sequence](sequence.html) that decodes UTF-8
and iterates over the code points, returning each as a number.