Go Package unicode: Difference between revisions
Jump to navigation
Jump to search
(4 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
The <code>unicode</code> package provide functions to evaluate the properties of runes inside strings. | The <code>unicode</code> package provide functions to evaluate the properties of runes inside strings. | ||
=Introspecting Characters= | =Introspecting Characters= | ||
Also see: {{Internal|Go_Strings# | Also see: {{Internal|Go_Strings#Introspecting_Characters|Strings | Introspecting Charancters}} | ||
====<tt>IsDigit()</tt>==== | ====<tt>IsDigit()</tt>==== | ||
<syntaxhighlight lang='go'> | |||
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)) | |||
</syntaxhighlight> | |||
prints: | |||
<syntaxhighlight lang='text'> | |||
char: A, is digit: false | |||
char: 1, is digit: true | |||
</syntaxhighlight> | |||
====<tt>IsSpace()</tt>==== | |||
====<tt>IsLetter()</tt>==== | |||
====<tt>IsLower()</tt>==== | |||
====<tt>IsPunct()</tt>==== | |||
=Conversions= | |||
====<tt>ToUpper()</tt>==== | |||
====<tt>ToLower()</tt>==== |
Latest revision as of 03:28, 22 August 2023
External
Internal
Overview
The unicode
package provide functions to evaluate the properties of runes inside strings.
Introspecting Characters
Also see:
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