how to convert array of bytes to string in golang?
September 11, 2022Hi Friends 👋,
Welcome To aGuideHub! ❤️
To convert array of bytes to string in golang, just use string()
method it will convert array of bytes to string. Only you have to pass array of bytes in the string()
.
Follow the below tutorial if you are struggling with installing GO in windows.
https://aguidehub.com/blog/how-to-install-golang-in-windows/
Today, I will show you how do I convert array of bytes to string in golang, as above mentioned I’m going to use string()
way.
Let’s start our Golang convert array of bytes to string example
main.go
package main
import "fmt"
func main() {
data := []byte{102, 97, 108, 99, 111, 110}
fmt.Println(data)
fmt.Println(string(data))
}
In the above example, we have converted type []byte
to string and printed in golang console. let’s check the output.
Output
[102 97 108 99 111 110]
falcon
I hope it helps you, All the best 👍.