package main
import(
"fmt"
"strconv"
)
func main(){
var b bool
var str string = "true"
//strconv.ParseBool(str)函数会返回两个值(value bool,err erro)
//只想获取 value bool , 不想获取 err 所以使用 _ 忽略
b, _ = strconv.ParseBool(str)
fmt.Printf("b type is %T b = %v\n", b , b)
}
输出结果为:
案例二:
func ParseInt(s string, base int, bitSize int) (i int64, err error)
var str string = "31415926"
var n1 int64
var n2 int
n1, _ = strconv.ParseInt(str, 10, 64)
fmt.Printf("n1 type is %T n1 = %v\n", n1 , n1)
n2 = int(n1)
fmt.Printf("n2 type is %T n2 = %v\n", n2 , n2)