y07k2
y07k2

Reputation: 2052

Parse whitespaces from String value to HTTP url standard

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"

Upvotes: 0

Views: 112

Answers (1)

Leonid Veremchuk
Leonid Veremchuk

Reputation: 1963

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

Output :

Oklahoma%20%City

Upvotes: 1

Related Questions