strconv.AppendBool() Function in Golang With Examples
Last Updated :
21 Apr, 2020
Go language provides inbuilt support to implement conversions to and from string representations of basic data types by strconv Package. This package provides an AppendBool() function which is used to append bool(i.e, true or false) according to the value of num2 to num1 and returns the extended buffer as shown in the syntax. To access AppendBool() function you need to import strconv Package in your program.
Syntax:
func AppendBool(num1 []byte, num2 bool) []byte
Example 1:
package main
import (
"fmt"
"strconv"
)
func main() {
val := []byte( "Is Bool: " )
val = strconv.AppendBool(val, true )
fmt.Println(string(val))
}
|
Output:
Is Bool: true
Example 2:
package main
import (
"fmt"
"strconv"
)
func main() {
val := []byte( "Append Bool:" )
fmt.Println(string(val))
fmt.Println( "Length(Before): " , len(val))
fmt.Println( "Capacity(Before): " , cap(val))
val = strconv.AppendBool(val, true )
fmt.Println(string(val))
fmt.Println( "Length(After): " , len(val))
fmt.Println( "Capacity(After): " , cap(val))
}
|
Output:
Append Bool:
Length(Before): 12
Capacity(Before): 12
Append Bool:true
Length(After): 16
Capacity(After): 32
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...