How to convert utf-8 string to utf-16-be string

How do I convert utf-8 strings to utf-16-be? i saw a python snippet to this filename.encode('utf-16be') on a string, can’t find equivalent go snippet.

So far I found this which does utf-16-be to utf-8.

There’s a simpler utility here you can use:

This makes a new encoding that you can use to get a decoder or encoder:

s := myutf16String
decoder := unicode.UTF16(unicode.LittleEndian, unicode.UseBOM).NewDecoder()
utf8,err := decoder.String(s)

thanks, this is exactly what I was looking for

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.