Golang : Get escape characters \u form from unicode characters
Problem :
You want to get the escape characters (\u form) from unicode characters(utf-8). How to do that?
Solution :
Use Printf %+q verb to translate the unicode characters to their escape characters. See code example below :
package main
import (
"fmt"
)
func main() {
russian := "Россия"
fmt.Printf("Россия escape form is %+q\n", russian)
japanese := "おはよう"
fmt.Printf("おはよう escape form is %+q\n", japanese)
}
Output :
Россия escape form is "\u0420\u043e\u0441\u0441\u0438\u044f"
おはよう escape form is "\u304a\u306f\u3088\u3046"
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+9.9k Golang : Translate language with language package example
+9.2k Golang : How to control fmt or log print format?
+5.9k Fontello : How to load and use fonts?
+10.5k RPM : error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
+11.6k Golang : Secure file deletion with wipe example
+7.5k Android Studio : AlertDialog to get user attention example
+10.1k Golang : Find and replace data in all files recursively
+9.9k Golang : Channels and buffered channels examples
+10.7k Golang : Get currencies exchange rates example
+10.8k Golang : How to transmit update file to client by HTTP request example
+48.5k Golang : Upload file from web browser to server
+6.5k Elasticsearch : Shutdown a local node