Home >Backend Development >Golang >How to determine whether a string is a number in golang

How to determine whether a string is a number in golang

尚
Original
2019-12-26 09:15:3113439browse

How to determine whether a string is a number in golang

Golang's method to determine whether it is a number:

IsNumber determines whether r is a numeric character (category N)

func IsNumber(r rune) bool
func main() {
s := "Hello 123123!"
for _, r := range s {
fmt.Printf("%c = %v\n", r, unicode.IsNumber(r))
} // 123123 = true
}

IsDigit determines r Whether it is a decimal numeric character

func IsDigit(r rune) bool
func main() {
s := "Hello 123123!"
for _, r := range s {
fmt.Printf("%c = %v\n", r, unicode.IsDigit(r))
} // 123123 = true
}

For more golang knowledge, please pay attention to the golang tutorial column.

The above is the detailed content of How to determine whether a string is a number in golang. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn