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
+5.2k Golang : Create new color from command line parameters
+19.8k Golang : How to get time zone and load different time zone?
+8k Golang : How to check if a string with spaces in between is numeric?
+40.8k Golang : Get hardware information such as disk, memory and CPU usage
+9.5k Golang : Get UDP client IP address and differentiate clients by port number
+15.4k Golang : How to implement two-factor authentication?
+24.6k Mac/Linux and Golang : Fix bind: address already in use error
+35.6k Upload multiple files with Go
+8.4k Golang : Format strings to SEO friendly URL example
+14.5k Golang : Read large file with bufio.Scanner cause token too long error
+18.3k Golang : Close channel after ticker stopped example
+6.8k Golang : Error reading timestamp with GORM or SQL driver