doc: add note on converting byte to escaped string (#11098)

pull/11100/head
Gavin Zhao 2021-08-07 21:52:05 -04:00 committed by GitHub
parent e32c65c322
commit 5e7cf56755
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -482,8 +482,15 @@ s[0] = `H` // not allowed
```
> 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
to bytes in the string, not Unicode code points.
Note that indexing a string will produce a `byte`, not a `rune` nor another `string`.
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 `