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.8k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations
+14.2k Golang : Missing Bazaar command
+9.9k Golang : Convert file unix timestamp to UTC time example
+8.9k Golang : Play .WAV file from command line
+8.7k Golang : Serving HTTP and Websocket from different ports in a program example
+24.6k Golang : convert rune to integer value
+51.5k Golang : How to get time in milliseconds?
+20.2k PHP : Convert(cast) int to double/float
+5.4k Linux : Disable and enable IPv4 forwarding
+5k Golang : Reclaim memory occupied by make() example
+13.5k Golang : convert rune to unicode hexadecimal value and back to rune character
+17.2k Golang : Read data from config file and assign to variables