How can I convert a string to a byte array that is compiled with a given encoding in Go?
In java, we can use the String: byte [] getBytes (charset charset) method. This method Encodes a string into a sequence of bytes using the given encoding, storing the result in a new byte array.
But how do you do this in GO? Is there a similar way in Go can do this?
Please let me know.
source to share
The Go standard library only supports Unicode (UTF-8, UTF-16, UTF-32) and ASCII encodings. ASCII is a subset of UTF-8.
The go-charset package (found here ) supports conversion to and from UTF-8, as well as links to the iconU library.
See also the field CharsetReader
in encoding / xml.Decoder .
I believe here is the answer: fooobar.com/questions/894196 / ...
There is no way to do this without recording the conversion yourself or using a third party package. You can try: http://code.google.com/p/go-charset
source to share