According to my understanding, a string in V is wrapped around a byte array encoded as UTF-8. That way, iterating over all string elements returns the bytes:
fn main() {
s := 'a string with äöü (umlauts)'
println(s)
for i := 0; i < s.len; i++ {
print('-')
}
println('')
}
resulting in (note the longer underlining):
a string with äöü (umlauts)
------------------------------
How to get the length of the string in characters/runes? How to iterate over all characters/runes instead of bytes?
It looks like one needs to use the
encoding.utf8
module: