Go语言中有关字符串替换函数的介绍

栏目: Go · 发布时间: 5年前

func main() {
	//转换为字符串后追加到字节数组
	slice := make([]byte, 1024)
	slice = strconv.AppendBool(slice, true)
	//第二个数为要追加的数,第三个数为指定10进制方式追加
	slice = strconv.AppendInt(slice, 1234, 10)
	slice = strconv.AppendQuote(slice, "abcgohello")

	fmt.Println("slice = ", string(slice))

	//其它类型转换为字符串
	var str string
	str = strconv.FormatBool(false)
	fmt.Println("str = ", str)
	//'f'指打印格式,以小数形式,-1指小数点位数,64以float64处理
	str = strconv.FormatFloat(3.14, 'f', -1, 64)
	fmt.Println("str = ", str)

	//整型转字符型
	str = strconv.Itoa(6666)
	fmt.Println("str = ", str)

	//字符串转其它类型
	flag, err := strconv.ParseBool("true")
	if err != nil {
		fmt.Println("err = ", err)
	}
	fmt.Println("flag = ", flag)

	//字符串转换为整型
	a, _ := strconv.Atoi("56479")
	fmt.Println("a = ", a)

}
  • 输出

Go语言中有关字符串替换函数的介绍


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Web Design DeMYSTiFieD

Web Design DeMYSTiFieD

Willard, Wendy / 2010-11 / $ 24.86

Website Design just got a whole lot easier! This title helps you to learn the latest website development tools, techniques, and best practices. "Web Design Demystified" provides the hands-on help you ......一起来看看 《Web Design DeMYSTiFieD》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具