Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -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))
}
}

View file

@ -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))
}