1

I want to write a function that takes a string and cleans it form url un-friendly characters, using a regular expression or something else, how can this be achieved? Thanks

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
user1010572
  • 469
  • 1
  • 4
  • 16
  • 1
    What's an "unfriendly" character? You mean as a URL? – dmon Jun 26 '12 at 17:20
  • for example a space, #, ? .... thanks – user1010572 Jun 26 '12 at 17:25
  • 1
    Perhaps you meant "encode"? http://stackoverflow.com/questions/3286067/url-encoding-in-android – dmon Jun 26 '12 at 17:26
  • 1
    You can use URLEncoder.encode, or something like: private static String encodeForUrl(String input) { return input.toLowerCase().replaceAll("[^a-z\\s]", "").replaceAll("\\s", "-"); } to manually replace all non-URL-friendly characters – Cruceo Jun 26 '12 at 17:28
  • Android is an operating system. You are not writing a function in an operating system. You are writing a method in Java. – CommonsWare Jun 26 '12 at 18:25
  • Try this: http://stackoverflow.com/questions/3286067/url-encoding-in-android – Calvin Jan 24 '13 at 13:40

0 Answers0