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
+8.1k Android Studio : Rating bar example
+13.1k Golang : Handle or parse date string with Z suffix(RFC3339) example
+30.5k Golang : Remove characters from string example
+13.9k Golang : Compress and decompress file with compress/flate example
+16.1k Golang : Loop each day of the current month example
+6.1k Linux/Unix : Commands that you need to be careful about
+15.4k Golang : Force download file example
+30.3k Golang : Generate random string
+7.7k Golang : Load DSA public key from file example
+10.5k Android Studio : Simple input textbox and intercept key example
+11.8k Golang : How to parse plain email text and process email header?
+19.3k Golang : Fix cannot download, $GOPATH not set error