Is there a better way to deal with reserved characters when parsing XML/JSON data on the iPhone?
- by Charles S.
The following code works, but it's ugly and creates a bunch of autoreleased objects. I'm using similar code for parsing reserved HTML characters as well (for quotes, & symbols, etc). I'm just wondering... Is there a cleaner way?
NSString *result = [[NSString alloc] initWithString:userInput];
NSString *result2 = [result stringByReplacingOccurrencesOfString:@"#"
withString:@"\%23"];
NSString *result3 = [result2 stringByReplacingOccurrencesOfString:@" "
withString:@"\%20"];
formatted = [[result3 stringByReplacingOccurrencesOfString:@"&"
withString:@"\%26"] retain];
[result release];