开发者

Android- remove URL percent symbols from string

I have a URL tha开发者_如何学编程t looks like this:

Liberty%21%20ft.%20Whiskey%20Pete%20-%20Thunderfist%20%28Original%20Mix%29.mp3

I'm trying to extract just the words from it. Right now, I'm using string.replace("%21", "!") for each and every %20, %29, etc. because each segment represent different characters or spaces. Is there a way to just covert those symbols and numbers to what they actually mean?

Thanks.


Those symbols are URLEncoded representations of characters that can't legally exist in a URL. (%20 = a single space, etc)

You need to UrlDecode those strings:

http://icfun.blogspot.com/2009/08/java-urlencode-and-urldecode-options.html

Official documentation here:
http://download.oracle.com/javase/6/docs/api/java/net/URLDecoder.html


It seems the input string is written using the URL encoding. Instead of writing all possible replacements manually (you can hardly cover all possibilities), you can use URLDecoder class in Java.

String input = "Liberty%21%20ft.%20Whiskey%20Pete...";
String decoded = URLDecoder.decode(input, "UTF-8");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜