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
+6.2k Javascript : Get operating system and browser information
+5.4k Python : Create Whois client or function example
+5.4k Golang : Calculate half life decay example
+12.3k Golang : md5 hash of a string
+9.9k Golang : Qt get screen resolution and display on center example
+23.1k Golang : Calculate time different
+8.9k Golang : Find duplicate files with filepath.Walk
+8.1k Setting $GOPATH environment variable for Unix/Linux and Windows
+27.1k Golang : Force your program to run with root permissions
+6.5k Golang : Break string into a slice of characters example
+21.1k Golang : Convert PNG transparent background image to JPG or JPEG image
+11.6k Golang : Change date format to yyyy-mm-dd