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
+4.8k Golang : Calculate a pip value and distance to target profit example
+29.1k Golang : missing Git command
+43.1k Golang : Get hardware information such as disk, memory and CPU usage
+18.3k Golang : Aligning strings to right, left and center with fill example
+22k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+5.3k How to check with curl if my website or the asset is gzipped ?
+9.6k PHP : Get coordinates latitude/longitude from string
+15.3k Golang : invalid character ',' looking for beginning of value
+5.2k Golang : Get FX sentiment from website example
+13k Golang : How to get a user home directory path?
+17.5k Golang : [json: cannot unmarshal object into Go value of type]
+21.9k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."