unicode

Guided tour · Formatting & Strings · pkg.go.dev →

Rune classification and simple case conversion. The 'is this a letter / digit / space' answers.

Classifier functions

IsLetter, IsDigit, IsSpace, IsPunct

unicode.IsLetter('é')  // true
unicode.IsDigit('7')   // true
unicode.IsSpace(' ')   // true
unicode.IsPunct(',')   // true

IsUpper, IsLower, IsTitle

unicode.IsUpper('A')   // true
unicode.IsLower('a')   // true

In / Is — check a rune against ranges

unicode.Is checks one RangeTable; unicode.In accepts many. Ranges like unicode.Latin, unicode.Greek, unicode.Han let you test scripts.

unicode.In('π', unicode.Greek)  // true
unicode.Is(unicode.Han, '汉')    // true

Case conversion — single rune

ToUpper, ToLower, ToTitle

These operate per-rune. For full strings use strings.ToUpper etc.

unicode.ToUpper('ß')  // 'ß' — simple fold
unicode.ToLower('E')  // 'e'