diff --git a/base/strconv/main.go b/base/strconv/main.go new file mode 100644 index 0000000..109e528 --- /dev/null +++ b/base/strconv/main.go @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" + "strconv" +) + +func main() { + str := "10000" + fmt.Printf("%T %#v\n", str, str) + + // 字符串转 int64 + i, _ := strconv.ParseInt(str, 10, 64) + fmt.Printf("%T %#v\n", i, i) + + // int 转 字符串 + str = strconv.Itoa(int(i)) + fmt.Printf("%T %#v\n", str, str) + + // 字符串转 bool + str = "true" + b, _ := strconv.ParseBool(str) + fmt.Printf("%T %#v\n", b, b) +}