I can't convert a String to UTF-8 in android. please help me!!
s1=URLEncoder.encode("臺北市")
result : %EF%BF%BDO%EF%BF%BD_%EF%BF%BD%EF%BF%BD
But "臺北市
" should be encoded as "%E8%87%BA%E5%8C%97%E5%B8%82
"
I can't convert a String to UTF-8 in android. please help me!!
s1=URLEncoder.encode("臺北市")
result : %EF%BF%BDO%EF%BF%BD_%EF%BF%BD%EF%BF%BD
But "臺北市
" should be encoded as "%E8%87%BA%E5%8C%97%E5%B8%82
"
In http://developer.android.com/reference/java/net/URLEncoder.html you can read that the you used is deprecated and that you should use
static String encode(String s, String charsetName)
So
URLEncoder.encode("臺北市", "utf-8")
should do the trick.You can convert your string using StringFormatter class to your code.
You want to convert to UTF-8:
You want to convert UTF-8 to normal format:
You can just use,
This will encode your "string: in UTF-8 format.
Put it in a try/catch and check for IllegalArgumentException if you want to. And if you have any spaces in your string, please replace it with
use this: