How to convert a string to slice of bytes in Go

1 Answer

0 votes
package main

import (
	"fmt"
)

func main() {
    s := "golang"
    b := []byte(s)
	
    fmt.Println(b)
    fmt.Printf("%s", b)	
}



/*
run:

[103 111 108 97 110 103]
golang

*/

 



answered May 25, 2020 by avibootz

Related questions

2 answers 211 views
2 answers 229 views
1 answer 260 views
2 answers 274 views
2 answers 215 views
2 answers 207 views
...