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
+14.9k Golang : Send email with attachment(RFC2822) using Gmail API example
+18k Golang : How to make a file read only and set it to writable again?
+10k Golang : Turn string or text file into slice example
+33.8k Golang : How to check if slice or array is empty?
+21.9k Golang : How to reverse slice or array elements order
+10.3k Golang : Text file editor (accept input from screen and save to file)
+10.4k Golang : Convert file content to Hex
+27k Golang : Find files by extension
+8.4k Golang : Configure Apache and NGINX to access your Go service example
+9.1k Golang : What is the default port number for connecting to MySQL/MariaDB database ?
+17.1k Golang : Get number of CPU cores
+30.6k Get client IP Address in Go