Home »
Golang »
Golang Reference
Golang unicode.IsNumber() Function with Examples
Golang | unicode.IsNumber() Function: Here, we are going to learn about the IsNumber() function of the unicode package with its usages, syntax, and examples.
Submitted by IncludeHelp, on September 17, 2021
unicode.IsNumber()
The IsNumber() function is an inbuilt function of the unicode package which is used to check whether the given r rune is a number (category N – the set of Unicode number character).
It accepts one parameter (r rune) and returns true if rune r is a number character; false, otherwise.
Syntax
func IsNumber(r rune) bool
Parameters
- r : Rune type value to be checked whether it is a number character or not.
Return Value
The return type of the unicode.IsNumber() function is a bool, it returns true if rune r is a number character; false, otherwise.
Example 1
// Golang program to demonstrate the
// example of unicode.IsNumber() Function
package main
import (
"fmt"
"unicode"
)
func main() {
fmt.Println("unicode.IsNumber('1'):",
unicode.IsNumber('1'))
fmt.Println("unicode.IsNumber('9'):",
unicode.IsNumber('9'))
fmt.Println("unicode.IsNumber('Ⅱ'):",
unicode.IsNumber('Ⅱ'))
fmt.Println("unicode.IsNumber('Ⅻ'):",
unicode.IsNumber('Ⅻ'))
fmt.Println("unicode.IsNumber('ⅱ')",
unicode.IsNumber('ⅱ'))
fmt.Println("unicode.IsNumber('ⅻ'):",
unicode.IsNumber('ⅻ'))
fmt.Println("unicode.IsNumber('g'):",
unicode.IsNumber('g'))
}
Output:
unicode.IsNumber('1'): true
unicode.IsNumber('9'): true
unicode.IsNumber('Ⅱ'): true
unicode.IsNumber('Ⅻ'): true
unicode.IsNumber('ⅱ') true
unicode.IsNumber('ⅻ'): true
unicode.IsNumber('g'): false
Example 2
// Golang program to demonstrate the
// example of unicode.IsNumber() Function
package main
import (
"fmt"
"unicode"
)
func main() {
var r rune
var result bool
r = 'ⅻ'
result = unicode.IsNumber(r)
if result == true {
fmt.Printf("%c is a number character.\n", r)
} else {
fmt.Printf("%c is not a number character.\n", r)
}
r = '8'
result = unicode.IsNumber(r)
if result == true {
fmt.Printf("%c is a number character.\n", r)
} else {
fmt.Printf("%c is not a number character.\n", r)
}
r = 'Q'
result = unicode.IsNumber(r)
if result == true {
fmt.Printf("%c is a number character.\n", r)
} else {
fmt.Printf("%c is not a number character.\n", r)
}
}
Output:
ⅻ is a number character.
8 is a number character.
Q is not a number character.
Golang unicode Package »