how to convert array of bytes to string in golang?

Hi 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 👍.

Try it Yourself

Premium Content

You can get all the below premium content directly in your mail when you subscribe us

Books

Interview Questions

Soon You will get CSS, JavaScript, React Js, and TypeScript So Subscribe to it.

Portfolio Template

View | Get Source Code

Cheat Sheets

Cheat Sheets Books are basically Important useful notes which we use in our day-to-day life.

Related Posts