zoukankan      html  css  js  c++  java
  • go字符串转换




    package main import (
    "fmt" "strconv" ) /* 常用总结 1、str 转 int a, _ := strconv.Atoi("780") 2、int 转 str str = strconv.Itoa(8888) */ func main() { s := make([]byte, 0, 1024) s = strconv.AppendBool(s, true) s = strconv.AppendInt(s, 124, 10) s = strconv.AppendQuote(s, "hello world") fmt.Println(string(s)) //true124"hello world" // 其他类型转换为字符串 var str string str = strconv.FormatBool(false) // f 打印格式 以小数方式,-1指小数点位数 64 float64 处理 str = strconv.FormatFloat(3.14, 'f', -1, 64) fmt.Println(str) //true124"hello world" // int 转 字符串 str = strconv.Itoa(8888) fmt.Println(str) //888 // 字符串转其他类型 var flag bool var err error flag, err = strconv.ParseBool("true") if err == nil { fmt.Println(flag) } else { fmt.Println(err) } // str 转int a, _ := strconv.Atoi("780") fmt.Println(a) }
  • 相关阅读:
    Test1
    排序之快速排序
    java注解
    排序之插入排序
    java IO之输出流——OutputStream
    java IO之输入流——InputStream
    行为模式之中介者
    行为模式之命令
    行为模式之职责链
    结构型模式总结
  • 原文地址:https://www.cnblogs.com/lpwlpw/p/9999735.html
Copyright © 2011-2022 走看看