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
+26.1k Golang : Record voice(audio) from microphone to .WAV file
+13.9k Golang : How to get Unix file descriptor for console and file
+5.6k Golang : When to use make or new?
+12.7k Golang : How to convert a number to words
+9.1k Golang : Read file and convert content to string
+4.2k Golang : Constant and variable names in native language
+33.7k Golang : Strip slashes from string example
+7.9k Golang : Intercept and compare HTTP response code example
+5.6k Unix/Linux : How to get own IP address ?
+11.9k Golang : Increment string example
+12.8k Golang : Chunk split or divide a string into smaller chunk example
+5k Golang : Calculate US Dollar Index (DXY)