how to convert byte array to string in golang?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

To convert byte array to string in golang, use the string() method it will convert your array to string and return the converted 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 byte array to string in golang, as above mentioned I’m going to use the string() method.

To use the string() method, we have to pass the byte array as a parameter then the string method will convert and return the byte array as a string.

Let’s start our Golang convert byte array to string example

main.go

package main

import (
    "fmt"
)

func main() {
    byteArray := []byte{'a', 'G', 'u', 'i', 'd', 'e', 'H', 'u', 'b'}
    str1 := string(byteArray[:])
    fmt.Println("String =", str1)
}

Output

OUTPUT

String = aGuideHub
[T+0000ms]
Program exited.

I hope it helps you, All the best 👍.

Follow me on Twitter