golang 去除字符串首尾空格
str := " dfghhj "
str = strings.TrimSpace(str)
字符串转 float64
package main
import (
"io"
"log"
"os"
"strconv"
)
func main() {
log.SetOutput(io.MultiWriter(os.Stdout))
log.SetFlags(log.Lshortfile)
num1 := "100"
// 字符串转 float64
vF1, _ := strconv.ParseInt(num1, 10, 64)
log.Printf("typt=%T value=%v", vF1, vF1)
}
main.go:18: typt=int64 value=100
golang 字符串转int
string转成uint64:
argUint64, _ := strconv.ParseUint(arg, 10, 64)
*string转成int:
int, err := strconv.Atoi(string)
string转成int64:
int64, err := strconv.ParseInt(string, 10, 64)
int转成string:
string := strconv.Itoa(int)
int64转成string:
string := strconv.FormatInt(int64,10)