doc: add note on converting byte to escaped string (#11098)
parent
e32c65c322
commit
5e7cf56755
11
doc/docs.md
11
doc/docs.md
|
@ -482,8 +482,15 @@ s[0] = `H` // not allowed
|
||||||
```
|
```
|
||||||
> error: cannot assign to `s[i]` since V strings are immutable
|
> error: cannot assign to `s[i]` since V strings are immutable
|
||||||
|
|
||||||
Note that indexing a string will produce a `byte`, not a `rune`. Indexes correspond
|
Note that indexing a string will produce a `byte`, not a `rune` nor another `string`.
|
||||||
to bytes in the string, not Unicode code points.
|
Indexes correspond to bytes in the string, not Unicode code points. If you want to
|
||||||
|
convert the `byte` to a `string`, use the `ascii_str()` method:
|
||||||
|
|
||||||
|
```v
|
||||||
|
country := 'Netherlands'
|
||||||
|
println(country[0]) // Output: 78
|
||||||
|
println(country[0].ascii_str()) // Output: N
|
||||||
|
```
|
||||||
|
|
||||||
Character literals have type `rune`. To denote them, use `
|
Character literals have type `rune`. To denote them, use `
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue