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

Release: 2019-12-26 09:15:31
Original
13438 people have browsed it

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
}
Copy after login

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
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template