how to convert string to byte in golang?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

To convert string to byte in golang, just use []byte and assign your value it will convert string to byte. Only you have to pass string into an byte.

Follow the below tutorial if you are struggling with installing GO in windows.

Today, I will show you how do I convert string to byte in golang, as above mentioned I’m going to use []byte way.

Let’s start our Golang convert string to byte example

Convert whole string into an array example


package main
import "fmt"

func main() {
  s:= "infinitbility"
  b:= []byte(s)

In the above example, we have converted string to byte and printed in golang console. let’s check the output.


[105 110 102 105 110 105 116 98 105 108 105 116 121]

Try it Yourself

I hope it helps you, All the best 👍.

Premium Content

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


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