請原諒我對這門語言的陌生。我找到了這個編碼為字節(jié)的示例,然后它使用 輸出fmt.Printf,但是我如何將這個示例的字符串表示形式存儲在變量中呢?src := []byte("Hello Gopher!")dst := make([]byte, hex.EncodedLen(len(src)))hex.Encode(dst, src)fmt.Printf("%s\n", dst) // output: 48656c6c6f20476f7068657221 (how do I get this output rather in a variable?我想設(shè)置dst一個變量,以便稍后在代碼中使用,而不是將其打印出來。我試圖弄清楚如何格式化 a hexwhich which was encoded from bytebut the example is printed out in fmt.Printfusing %s. 但我想格式化以在一個變量中使用,該變量可以在后面部分的代碼中重用。所以我不認(rèn)為這是標(biāo)記原因的重復(fù),因為它涉及格式化字符串,而不是字節(jié)的十六進(jìn)制
設(shè)置 %s 從字節(jié)編碼的十六進(jìn)制到變量 golang
ibeautiful
2023-06-01 09:53:44