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


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

查看所有标签

猜你喜欢:

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

Complexity and Approximation

Complexity and Approximation

G. Ausiello、P. Crescenzi、V. Kann、Marchetti-sp、Giorgio Gambosi、Alberto M. Spaccamela / Springer / 2003-02 / USD 74.95

This book is an up-to-date documentation of the state of the art in combinatorial optimization, presenting approximate solutions of virtually all relevant classes of NP-hard optimization problems. The......一起来看看 《Complexity and Approximation》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具