Friday, March 25, 2016

Bash: Converting Percent-encoded String to Multibyte String

Command:

$ a='%E7%B9%94%E7%94%B0%E4%BF%A1%E9%95%B7'
$ echo -e "${a//%/\\x}"


Output:


織田信長

Python: Converting Percent-encoded String to Multibyte String

Command:

$ python -c "import urllib, sys; print urllib.unquote(sys.argv[1])" %E7%B9%94%E7%94%B0%E4%BF%A1%E9%95%B7

Output:

織田信長

Python: Percent-encode Multibyte String

Percent-encode multibyte string:

$ python -c "import urllib, sys; print urllib.quote(sys.argv[1])" 織田信長

Output:

%E7%B9%94%E7%94%B0%E4%BF%A1%E9%95%B7

URL Encoding (Percent-encoding): Url with Multibyte Characters and Percent-encoded URL

https://ja.wikipedia.org/wiki/織田信長

is same as:

https://ja.wikipedia.org/wiki/%E7%B9%94%E7%94%B0%E4%BF%A1%E9%95%B7