Logo

Programming-Idioms

History of Idiom 137 > diff from v5 to v6

Edit summary for version 6 by programming-idioms.org:
New Go implementation by user [programming-idioms.org]

Version 5

2016-06-10, 21:46:29

Version 6

2016-06-10, 21:55:21

Idiom #137 Check if string contains only digits

Set boolean b to true if string s contains only characters in range '0'..'9', false otherwise.

Idiom #137 Check if string contains only digits

Set boolean b to true if string s contains only characters in range '0'..'9', false otherwise.

Imports
import "strings"
Code
isNotDigit := func(c rune) bool { return c < '0' || c > '9' }
b := strings.IndexFunc(s, isNotDigit) == -1
Doc URL
https://golang.org/pkg/strings/#IndexFunc
Demo URL
https://play.golang.org/p/wLy3_XFmeW