From 1419b92bc7c2467d7cccdc949de2d45732d92b1b Mon Sep 17 00:00:00 2001 From: Shikong <919411476@qq.com> Date: Sat, 16 Oct 2021 17:25:14 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20strconv=20=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base/strconv/main.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 base/strconv/main.go 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) +}