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
+10k Golang : Get escape characters \u form from unicode characters
+7.3k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+11.3k Golang : Calculate Relative Strength Index(RSI) example
+26.9k Golang : Convert file content into array of bytes
+11.6k Use systeminfo to find out installed Windows Hotfix(s) or updates
+13k Python : Convert IPv6 address to decimal and back to IPv6
+13.3k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+5.3k PHP : See installed compiled-in-modules
+18.3k Golang : Put UTF8 text on OpenCV video capture image frame
+23k Golang : Calculate time different
+18.1k Golang : Get all upper case or lower case characters from string example
+4.7k Adding Skype actions such as call and chat into web page examples