strconv.AppendUint() 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 AppendUint() function which is used to append the string form of the unsigned integer x, as generated by FormatUint, to num and return the extended buffer. Or in other words, this function converts the uint type integer x to a string and appends it to the end of num. To access AppendUint() function you need to import strconv Package in your program.
Syntax:
func AppendUint(num []byte, x uint64, base int) []byte
Example 1:
package main
import (
"fmt"
"strconv"
)
func main() {
val1 := []byte( "uint value (base 16): " )
val1 = strconv.AppendUint(val1, 35, 16)
fmt.Println(string(val1))
val2 := []byte( "uint value (base 10): " )
val2 = strconv.AppendUint(val2, 35, 10)
fmt.Println(string(val2))
}
|
Output:
uint value (base 16): 23
uint value (base 10): 35
Example 2:
package main
import (
"fmt"
"strconv"
)
func main() {
val1 := []byte( "uint value (base 16): " )
val1 = strconv.AppendUint(val1, 45, 16)
fmt.Println(string(val1))
fmt.Println( "Length: " , len(val1))
fmt.Println( "Capacity: " , cap(val1))
val2 := []byte( "uint value (base 10): " )
val2 = strconv.AppendUint(val2, 43, 10)
fmt.Println(string(val2))
fmt.Println( "Length: " , len(val2))
fmt.Println( "Capacity: " , cap(val2))
}
|
Output:
uint value (base 16): 2d
Length: 24
Capacity: 48
uint value (base 10):43
Length: 23
Capacity: 48
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...