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
+4.4k PHP : Hide PHP version information from curl
+6.7k Golang : Ways to recover memory during run time.
+12.6k Javascript : Prompt confirmation before exit
+12.4k Golang : Query string with space symbol %20 in between
+4.3k Golang : Qt update UI elements with core.QCoreApplication_ProcessEvents
+15.2k Golang : Convert slice to array
+5.8k CloudFlare : Another way to get visitor's real IP address
+5.5k Nginx : Password protect a directory/folder
+9.1k Golang : How to tokenize source code with text/scanner package?
+3.9k Which content-type(MIME type) to use for JSON data
+3.8k Linux/MacOSX : How to symlink a file?
+23.4k Golang : Create PDF file from HTML file