doc: string immutability example

pull/6369/head
Swastik Baranwal 2020-09-14 19:48:10 +05:30 committed by GitHub
parent f7a77f4041
commit 01b28ef1a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -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.