Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android- remove URL percent symbols from string

I have a URL that 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.

like image 469
Splitusa Avatar asked Aug 05 '11 16:08

Splitusa


1 Answers

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

like image 128
David Avatar answered Sep 29 '22 16:09

David