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

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

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语言中有关字符串替换函数的介绍


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

查看所有标签

猜你喜欢:

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

The Black Box Society

The Black Box Society

Frank Pasquale / Harvard University Press / 2015-1-5 / USD 35.00

Every day, corporations are connecting the dots about our personal behavior—silently scrutinizing clues left behind by our work habits and Internet use. The data compiled and portraits created are inc......一起来看看 《The Black Box Society》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具