From 01b28ef1a54a5fe513e26d8f721ab295b9e83255 Mon Sep 17 00:00:00 2001 From: Swastik Baranwal Date: Mon, 14 Sep 2020 19:48:10 +0530 Subject: [PATCH] doc: string immutability example --- doc/docs.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/docs.md b/doc/docs.md index 96dfbb0d45..4235625b2d 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -355,7 +355,14 @@ println(s) // "hello world" In V, a string is a read-only array of bytes. String data is encoded using UTF-8. -Strings are immutable. +Just like in Go and Java, strings are immutable, which means their values cannot be changed. + +The following code will raise an error: + +```v +mut s := 'hello' +s[0] = `H` +``` Both single and double quotes can be used to denote strings. For consistency, `vfmt` converts double quotes to single quotes unless the string contains a single quote character.