Skip to content

Instantly share code, notes, and snippets.

@hlxwell
Created May 2, 2013 03:16
Show Gist options
  • Save hlxwell/5499939 to your computer and use it in GitHub Desktop.
Save hlxwell/5499939 to your computer and use it in GitHub Desktop.
Define a static method, for escape string
static NSString* GAEscapeNSString(NSString* value) {
if (!value) return nil;
const char *chars = [value UTF8String];
NSMutableString *escapedString = [NSMutableString string];
while (*chars) {
if (*chars == '\\') {
[escapedString appendString:@"\\\\"];
} else if (*chars == '\'') {
[escapedString appendString:@"\\'"];
} else {
[escapedString appendFormat:@"%c", *chars];
}
++chars;
}
return escapedString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment