Doc: string examples
This commit is contained in:
parent
4aaffd6c44
commit
775751c67b
@ -194,6 +194,28 @@ Some arithmetic operators can also be used with strings.
|
||||
| [blue]`*` | _repeat_ | Make _n_ copy of a string | [blue]`"one" * 2` _["oneone"]_
|
||||
|===
|
||||
|
||||
The items of strings can be accessed using the dot `.` operator.
|
||||
|
||||
.Item access syntax
|
||||
[source,bnf]
|
||||
----
|
||||
<item> ::= <string-expr>"."<index-expr>
|
||||
----
|
||||
|
||||
.String examples
|
||||
[source,go]
|
||||
----
|
||||
`>>>` [blue]`s="abc"` [gray]`// assign the string to variable s`
|
||||
[geen]`abc`
|
||||
`>>>` [blue]`s.1` [gray]`// char at position 1 (starting from 0)
|
||||
[blue]`b`
|
||||
`>>>` [blue]`s.(-1)` [gray]`// char at position -1, the rightmost one
|
||||
[blue]`c`
|
||||
`>>>` [blue]`#s` [gray]`// number of chars
|
||||
[blue]3`
|
||||
`>>>` [blue]`#"abc"` [gray]`// number of chars
|
||||
[blue]3`
|
||||
----
|
||||
|
||||
=== Boolean
|
||||
Boolean data type has two values only: _true_ and _false_. Relational and Boolean expressions produce Boolean values.
|
||||
@ -293,6 +315,9 @@ The items of array can be accessed using the dot `.` operator.
|
||||
`>>>` [blue]`list.(-1)`
|
||||
[green]`three`
|
||||
`>>>` [blue]`list.(10)`
|
||||
[red]`Eval Error: [1:9] index 10 out of bounds`
|
||||
`>>>` [blue]`#list`
|
||||
[green]`3`
|
||||
----
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user