I am attempting to escape a specific hex value in a golang string. The function call looks something like this:
Insert(0, "\x00\x00\x00IHDR\x00\x00\x000\x00\x00\x000\b\x03") Insert(25, "\x00\x00\x00\x06PLTE") Insert(43, "\x00\x00\x00\x02tRNS") Insert(57, "\x00\x00\t;IDATx\xDA\x010\t\xCF\xF6") // problem line Insert(2432, "\x00\x00\x00\x00IEND")
The problem arises when the language interprets the "\xDA" hex escape. Instead of correctly escaping to a Ú value, it is escaped to � (the Replacement Character).
I ensured this is what was occuring in the following playground example:
fmt.Println("\xDA") i := 218 h := fmt.Sprintf("%x", i) fmt.Printf("Hex conf of '%d' is '%s' ", i, h) fmt.Println(string(i))
This snippet, when run, prints
� Hex conf of '218' is 'da' Ú
Here is the playground link: https://play.golang.org/p/c-XMK68maX