Created
May 12, 2020 15:34
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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