Go Package unicode: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 12: Line 12:
s := "A 10"
s := "A 10"
rs := []rune(s)
rs := []rune(s)
fmt.Printf("char: %c, is digit: %t\n", rs[0], unicode.IsDigit(rs[0]))
c := rs[0]
fmt.Printf("char: %c, is digit: %t\n", rs[2], unicode.IsDigit(rs[2]))
c2 := rs[2]
fmt.Printf("char: %c, is digit: %t\n", c, unicode.IsDigit(c))
fmt.Printf("char: %c, is digit: %t\n", c2, unicode.IsDigit(c2))
</syntaxhighlight>
</syntaxhighlight>
prints:
prints:

Revision as of 02:00, 22 August 2023

External

Internal

Overview

The unicode package provide functions to evaluate the properties of runes inside strings.

Introspecting Characters

Also see:

Strings | Introspecting Charancters

IsDigit()

s := "A 10"
rs := []rune(s)
c := rs[0]
c2 := rs[2]
fmt.Printf("char: %c, is digit: %t\n", c, unicode.IsDigit(c))
fmt.Printf("char: %c, is digit: %t\n", c2, unicode.IsDigit(c2))

prints:

char: A, is digit: false
char: 1, is digit: true