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
+9.4k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+25.8k Golang : Find files by name - cross platform example
+6.1k Linux : How to fix Brother HL-1110 printing blank page problem
+8.7k Golang : Load ASN1 encoded DSA public key PEM file example
+3.6k Java : Generate multiplication table example
+11.1k Golang : Encrypt and decrypt data with x509 crypto
+8.6k Golang : Eroding and dilating image with OpenCV example
+7.5k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+14.3k Golang : Get current time from the Internet time server(ntp) example
+25.4k Golang : Force your program to run with root permissions
+8.8k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+5.8k Golang : Output or print out JSON stream/encoded data