For a better understanding of this example, we always recommend you to learn the basic topics of Golang programming listed below:
The process of converting a byte array to a string is called decoding. This procedure requires a charset. Hough, we should use charset for decoding a byte array. A charset or character set refers to the composite number of different characters that are being used and supportedby the computer hardware and software.
Here we are showing how to convert the byte to string in the Go language. Here variable byteAr is holding the byte array to be converted. And variable str for holding the result string. Finally, the byte array is converted using string(byteAr) and print the result. Given below are the steps which are used in the Go program.
STEP 1: Import the package fmt
STEP 2: Start function main()
STEP 3: Declare the byte array variable byteAr
STEP 4: Consider variable str for holding the result string
STEP 5: The byte array is converted using string(byteAr)
STEP 6: Finally print the variable str using fmt.Println()
package main
import (
"fmt"
)
func main() {
byteAr := []byte{72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100}
var str string
str = string(byteAr)
fmt.Println(str)
}
Hello world