Skip to content

Instantly share code, notes, and snippets.

@vjeantet
Created November 1, 2025 12:11
Show Gist options
  • Save vjeantet/52ef24a2c95d30435f48a697618c59fd to your computer and use it in GitHub Desktop.
Save vjeantet/52ef24a2c95d30435f48a697618c59fd to your computer and use it in GitHub Desktop.
string to []byte
package main
import (
"fmt"
"strings"
)
func main() {
mystr := "Basic"
var e = fmt.Sprintf("%v", []byte(mystr))
e = strings.ReplaceAll(e, " ", ",")
e = strings.ReplaceAll(e, "]", "")
e = strings.ReplaceAll(e, "[", "")
fmt.Printf("string([]byte{%s})", e)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment