go AppendBool()

AppendBool()方法语法

func AppendBool(dst []byte, b bool) []byte

go源码对AppendBool()方法的介绍:

AppendBool appends "true" or "false", according to the value of b, to dst and returns the extended buffer.

即,golang的strconv.AppendBool(),可以将第二个参数的bool类型值转换为字符串表示,然后添加到dst切片之中,并返回一个新的切片,并不修改参数中的切片,类似于append(dst, FormatBool(b)...)。


strconv.AppendBool()方法实例代码

func main() {
	var bytes []byte
	new_bytes := strconv.AppendBool(bytes, true)
	fmt.Println(new_bytes)
	fmt.Println(bytes)
}

运行go文件,得到输出:

[116 114 117 101]
[]

全栈后端 / go语法 :













Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.