←back to thread

Go subtleties

(harrisoncramer.me)
235 points darccio | 2 comments | | HN request time: 0.001s | source
1. johnmaguire ◴[] No.45671374[source]
> Using len() with Strings, and UTF-8 Gotchas

Try utf8.RuneCountInString().

replies(1): >>45672551 #
2. gethly ◴[] No.45672551[source]
Problem with this is that it requires the whole string to be iterated over, byte by byte, or rune by rune, whereas len() does no such thing as the length is stored in the underlying type.