首页 > 其他 > 详细

go字符串转换

时间:2018-11-22 11:17:47      阅读:128      评论:0      收藏:0      [点我收藏+]



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) }

 

go字符串转换

原文:https://www.cnblogs.com/lpwlpw/p/9999735.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!