Skip to content
Related Articles

Related Articles

strconv.AppendBool() Function in Golang With Examples

View Discussion
Improve Article
Save Article
  • 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:




// Golang program to illustrate
// strconv.AppendBool() Function
package main
  
import (
    "fmt"
    "strconv"
)
  
func main() {
  
    // Using AppendBool() function
    val := []byte("Is Bool: ")
    val = strconv.AppendBool(val, true)
      
    fmt.Println(string(val))
  
}


Output:

Is Bool: true

Example 2:




// Golang program to illustrate
// strconv.AppendBool() Function
package main
  
import (
    "fmt"
    "strconv"
)
  
func main() {
  
    // Using AppendBool() function
    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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!