From 5e7cf567556928f3e3e5b59c74ab1c42e7a23a09 Mon Sep 17 00:00:00 2001 From: Gavin Zhao <74938940+GZGavinZhao@users.noreply.github.com> Date: Sat, 7 Aug 2021 21:52:05 -0400 Subject: [PATCH] doc: add note on converting byte to escaped string (#11098) --- doc/docs.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/doc/docs.md b/doc/docs.md index 1f0e218dce..2d0a770a2c 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -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 `