I’m looking for the equivalent of the stringByAddingPercentEscapesUsingEncoding method in Java (for Android).
I tried URLEncoder.encode() but it doesn’t do the same.
I don’t expect “/” or “:” to be “percent escaped” but “œ” (for example) should be.
Any ideas?
Edit:
I just don’t want http:// to become http%3a%2f%2f
Well if you want to leave
:and/untouched, I think you need to do it yourself, because that’s not valid percent-encoding and therefore there is little chance for a solution already existing in java. I also checked the documentation forstringByAddingPercentEscapesUsingEncodingand it doesn’t behave like that either.Comparing documentation,
URLEncoder.encode(string, encoding)is exactly the same as the NS method, so your requirement is indeed weird. Here’s the custom code anyway: