Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,19 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func isNumeric(s string) bool {
|
||||
_, err := strconv.ParseFloat(s, 64)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("Are these strings numeric?")
|
||||
strings := []string{"1", "3.14", "-100", "1e2", "NaN", "rose"}
|
||||
for _, s := range strings {
|
||||
fmt.Printf(" %4s -> %t\n", s, isNumeric(s))
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
func isInt(s string) bool {
|
||||
for _, c := range s {
|
||||
if !unicode.IsDigit(c) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("Are these strings integers?")
|
||||
v := "1"
|
||||
b := false
|
||||
if _, err := strconv.Atoi(v); err == nil {
|
||||
b = true
|
||||
}
|
||||
fmt.Printf(" %3s -> %t\n", v, b)
|
||||
i := "one"
|
||||
fmt.Printf(" %3s -> %t\n", i, isInt(i))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue