Created
March 6, 2012 23:04
-
-
Save ryanmaxwell/1989630 to your computer and use it in GitHub Desktop.
Escape NSString so that it can be passed to webview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSString *)stringByEscapingJSONReservedCharacters { | |
return [[[[[[[[self stringByReplacingOccurrencesOfString:@"\\\\" withString:@"☃"] /* \\ (single slash character) for snowman */ | |
stringByReplacingOccurrencesOfString:@"\\n" withString:@"\\\\n"] /* \n for \\n */ | |
stringByReplacingOccurrencesOfString:@"\\t" withString:@"\\\\t"] /* \t for \\t */ | |
stringByReplacingOccurrencesOfString:@"\\b" withString:@"\\\\b"] /* \b for \\b */ | |
stringByReplacingOccurrencesOfString:@"\\f" withString:@"\\\\f"] /* \f for \\f */ | |
stringByReplacingOccurrencesOfString:@"\\r" withString:@"\\\\r"] /* \r for \\r */ | |
stringByReplacingOccurrencesOfString:@"\\\"" withString:@"\\\\\""] /* \" for \\" */ | |
stringByReplacingOccurrencesOfString:@"☃" withString:@"\\\\\\\\"]; /* snowman for \\\\ (single slash character) */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment