golang 去除字符串首尾空格

  1. str := " dfghhj "
  2. str = strings.TrimSpace(str)

字符串转 float64

  1. package main
  2. import (
  3. "io"
  4. "log"
  5. "os"
  6. "strconv"
  7. )
  8. func main() {
  9. log.SetOutput(io.MultiWriter(os.Stdout))
  10. log.SetFlags(log.Lshortfile)
  11. num1 := "100"
  12. // 字符串转 float64
  13. vF1, _ := strconv.ParseInt(num1, 10, 64)
  14. log.Printf("typt=%T value=%v", vF1, vF1)
  15. }
  1. 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)