I have an NSString like this:
http://www.
But I want to transform it to this:
http%3A%2F%2Fwww.
How can I do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To escape the characters you want is a little more work.
Example code
NSLog output:
The following are useful URL encoding character sets:
Creating a characterset combining all of the above:
Creating a Base64
In the case of Base64 characterset:
Note:
stringByAddingPercentEncodingWithAllowedCharacterswill also encode UTF-8 characters needing encoding.Using Core Foundation Without ARC:
Note:
-stringByAddingPercentEscapesUsingEncodingwill not produce the correct encoding, in this case it will not encode anything returning the same string.stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncodingencodes 14 characrters:testString:
encodedString:
Note: consider if this set of characters meet your needs, if not change them as needed.
RFC 3986 characters requiring encoding (% added since it is the encoding prefix character):
Some “unreserved characters” are additionally encoded: