Skip to content

Instantly share code, notes, and snippets.

@thrawn01
Created May 12, 2020 15:34
Show Gist options
  • Save thrawn01/7c705b79e72f81d96edcaa876e1e3bf3 to your computer and use it in GitHub Desktop.
Save thrawn01/7c705b79e72f81d96edcaa876e1e3bf3 to your computer and use it in GitHub Desktop.
Take []byte output from printing with fmt.Printf("%v", myBytes) and convert it back into a golang []byte
package main
import (
"fmt"
"strings"
)
func main() {
// [ and ] have been manually removed
s := "76 105 99 32 83 105 110 100 105 97 32 78 117 241"
in := strings.Split(s, " ")
out := make([]byte, len(in))
for i, d := range in {
_, err := fmt.Sscan(d, &out[i])
if err != nil {
fmt.Printf("Err: %s\n", err)
}
}
fmt.Printf("out: %s\n", string(out))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment