I would like to know how I can apply the utf8 to a string in golang. Investigating in the documentation , do the following:
I am making a query to a database and in the field the following information is stored ANDRÉS NUÑEZ
when making the query, in the variable ANDR�S NU�EZ
is stored, after review, make the following code:
Variable structure:
type DataBD struct {
ID int
Nom_User string
}
Connection to the DB:
db, err := sql.Open("odbc", "DSN=" + host)
Code Utf8:
str := Data.nombre
for len(str) > 0 {
r, size := utf8.DecodeRuneInString(str)
log.Printf("%c %c\n", r, size)
str = str[size:]
}
But the result remains the same. I clarify that I am importing import "unicode/utf8"
.
RESULT:
2018/05/29 08:48:55 A
2018/05/29 08:48:55 N
2018/05/29 08:48:55 D
2018/05/29 08:48:55 R
2018/05/29 08:48:55 �
2018/05/29 08:48:55 S
2018/05/29 08:48:55
2018/05/29 08:48:55 N
2018/05/29 08:48:55 U
2018/05/29 08:48:55 �
2018/05/29 08:48:55 E
2018/05/29 08:48:55 Z