2 ms·
To clarify, Letting the length of a UTF-8 string in Go is O(1); it's computed and stored on the string header at creation.
by weberc2 10y ago
To clarify, Letting the length of a UTF-8 string in Go is O(1); it's computed and stored on the string header at creation.
- burntsushi 10y agoTo clarify even more: that length is the number of bytes (or UTF-8 code units) in the string. It doesn't corresponding to the number of characters (which one may either consider to be Unicode codepoints, or more technically correct, Unicode grapheme clusters). If you want to count the number of codepoints in a string (called "rune" in Go), then you need to do so explicitly: https://golang.org/pkg/unicode/utf8/#RuneCountInString https://golang.org/pkg/unicode/utf8/#RuneCountInString
- weberc2 10y agoTouché
- deleted 10y ago[deleted]
- deleted 10y ago[deleted]