How can i encode my NSString so all the special character for example & becomes & and \' becomes &apos?
I am not sure if encoding is the right word fo
What you are talking about is called HTML Entities.
There exists a category claiming to solve this: NSString+HTML.
For URL Escaping (while we're at it) use this:
@nterface NSString (Escaping)
- (NSString *)percentEscapedString
- (NSString *)percentUnescapedString
@end
@implementation NSString (Escaping)
- (NSString *)percentEscapedString {
return [self stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}
- (NSString *)percentUnescapedString {
return [self stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}
@end
Edit: As Dave pointed out weaknesses in my references solution, here are some related questions with lots of other solutions: