How to Use the unicode and unicode/utf8 Packages

The unicode and unicode/utf8 packages automatically support Unicode 17 in Go, providing functions to validate, count, and classify characters without manual configuration.

The unicode and unicode/utf8 packages are standard library components that automatically use Unicode 17 in Go versions that include this update, requiring no code changes. Use unicode/utf8 functions like Valid to check string validity or RuneCount to count characters correctly.

import "unicode/utf8"

s := "Hello, δΈ–η•Œ"
if utf8.ValidString(s) {
    count := utf8.RuneCountInString(s)
    // count is 8
}

The unicode package provides constants and functions for character properties, such as unicode.IsLetter or unicode.IsDigit, which also reflect the latest Unicode standard.

import "unicode"

r := 'A'
if unicode.IsLetter(r) {
    // r is a letter
}

No manual configuration is needed; the upgrade from Unicode 15 to 17 is handled by the Go toolchain and standard library implementation.