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.2k Linux : How to set root password in Linux Mint
+5.9k Golang : Struct field tags and what is their purpose?
+8.1k Golang : How to feed or take banana with Gorilla Web Toolkit Session package
+11.1k Golang : Get UDP client IP address and differentiate clients by port number
+18.7k Golang : Set, Get and List environment variables
+10.3k Golang : Edge detection with Sobel method
+10k Random number generation with crypto/rand in Go
+10.1k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+29.8k Golang : Saving(serializing) and reading file with GOB
+11k Golang : Command line file upload program to server example
+9.5k Golang : Create unique title slugs example
+9.6k Golang : Scramble and unscramble text message by randomly replacing words