FWIW, if you can use the satimage addition, it has an escapeURL
command which returns the url encoding for any characters you feed it.
set x to "悪㎯个"
escapeURL x
--> "%E6%82%AA%E3%8E%AF%E4%B8%AA"
Of course, you can feed it just a single character as well.
set x to "个"
escapeURL x
--> "%E4%B8%AA"
As an aside, if you only have a character or two to encode, you can get the url encoding using the Character Viewer (aka Emoji & Symbols). From within the viewer, search for the character.
Right-click on the resulting character and you should see a Copy character info
command. Click on it and then paste into an empty textedit window. You should see a result like this below.
个
CJK UNIFIED IDEOGRAPH-4E2A
Unicode: U+4E2A, UTF-8: E4 B8 AA
Take the hex numbers in the UTF-8 section, insert %
and remove the spaces. You now have the url encoding for the character.
It works in both directions. If you search for E4 B8 AA
then it will display the following:
Character
E4 B8 AA
Character code
个
Unfortunately, other than by using satimage’s escapeURL
command, I don’t know how to programmatically get the UTF-8 code so it’s not as versatile as it might be (or maybe it’s just me that’s not).