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.2k Golang : Check if integer is power of four example
+17.6k Golang : Parse date string and convert to dd-mm-yyyy format
+5.2k Golang : Calculate half life decay example
+18.4k Golang : Write file with io.WriteString
+13.6k Golang : Tutorial on loading GOB and PEM files
+7.3k Android Studio : How to detect camera, activate and capture example
+9.9k Golang : Channels and buffered channels examples
+6.2k Javascript : Generate random key with specific length
+13.9k Golang : How to check if a file is hidden?
+20.6k Golang : Secure(TLS) connection between server and client
+13.5k Golang : Query string with space symbol %20 in between