0

How can I get a parse String of city name without whitespaces (on the start and at the end) and with "%20" instead of " " (which contains some city names) in android.

For example I would like to parse:

" Oklahoma " -> "Oklahoma"

or

"    Oklahoma    City" -> "Oklahoma%20City"
1

1 Answer 1

1
Uri.encode(" Oklahoma  City".trim())  

Output :

Oklahoma%20%City

Sign up to request clarification or add additional context in comments.

2 Comments

"Oklahoma [space][space]City" Output: Oklahoma%20%20City ... should be " Oklahoma City".replaceAll("\\s+", " ").trim()
For me Leonid's code works fine. I get from geocode API what I need! But thanks you too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.