Decode UTF-8 string

Hey there, does anyone know how can I decode a UTF-8 string? Can’t find it on Google no where.

tnx.

What exactly do you mean by “decode UTF-8 string”? What do you want to decode the string into?

2 Likes

Go strings are UTF8 by default. If you mean how to convert another encoding to UTF-8 or vice versa can use the package here to do so:

Here is an example (under Translating encodings):

https://kennygrant.gitbooks.io/go-bestiary/content/strings.html

1 Like

It’s a string came through http request, the request is made by an Android app which encodes every parameter value to UTF-8. I guess I gotta decode it, right?

It’s a parameter passed through a http request, request made by an Android app which encodes every parameter value to UTF-8 .

If the data comes in as a []byte and is in utf-8, just converting it to a string does the right thing.

If this is not your situation, show code.

You don’t necessary need to decode a UTF-8 string. You can always use it directly in UTF-8 form. Unless, of course, there is some mistake in your understanding to the encoding you’ve got.

Can you show us some “encoded” text with the expected “decoded” version?

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