ivhome
ivhome

Reputation: 23

How convert unicode string from database to utf-string in Go?

String is stored in database as unicode "\u0435\u043e ..." (table's encoding is UTF-8).

After selecting from database and printing:

log.Println(str)

OUT: \u0435\u043e...

How can I transform this string to utf presentation?

Upvotes: 0

Views: 134

Answers (1)

Not_a_Golfer
Not_a_Golfer

Reputation: 49157

To decode the string you have, you can do:

import "net/url"

...

url.QueryUnescape("\u0435\u043e")

But I think there's a misconfiguration of your database or connection parameters, as this should be handled automatically. This is not utf-8 BTW.

Upvotes: 2

Related Questions