Home >Backend Development >Golang >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!