So i started with a message as a string, turned it into a byte array and printed it, I've now lost the original string but have the string output of the byte array. I want my string back. (don't ask me why i did this or how... I didn't really, this is just for illustration purposes).
Essentially the bit I'm missing is a convenient way to turn the printed representation of a byte array back into a byte array.
See the example below to explain better what I'm trying to do (complete 'otherWay' func):
package main
import (
"fmt"
)
func main() {
// started with originalString and lost it
originalString := "I'm a string I am!"
// I have the output of 'oneWay()' in my clipboard, so could paste into code
golangStringFormatOfByteArray := oneWay(originalString)
fmt.Println("String as bytes:", golangStringFormatOfByteArray )
// get original string back
returnString := otherWay(golangStringFormatOfByteArray )
fmt.Println("Original String:", returnString )
}
func oneWay(theString string) string {
theStringAsBytes := []byte(theString)
golangStringFormatOfByteArray := fmt.Sprintf("%v", theStringAsBytes)
return golangStringFormatOfByteArray
}
func otherWay(stringFormat string) string {
// how do I get the original string back
return "I want you back"
}