mirror of
https://gitee.com/shikong-sk/golang-study
synced 2025-02-22 23:12:15 +08:00
docs: strconv 字符串转换
This commit is contained in:
parent
656dfbac05
commit
1419b92bc7
24
base/strconv/main.go
Normal file
24
base/strconv/main.go
Normal file
@ -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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user