I need an efficient piece of code that strips escape characters. This is regular escapes not HTML escape characters.
Example: "\"", "\\\\", "\", "\\"
I want a general algorithm to strip any kind of escape sequences.
Could use any utility like regular expression.
(NSString*) unescape:(NSString*) string {
....
}
This is the answer I wrote:
-(NSString*) unescape:(NSString*) string
{
for(int i = 0; i < string.length; i++) {
char a = [string characterAtIndex:i];
if([string characterAtIndex:i] == '\\' ) {
string = [string stringByReplacingCharactersInRange:NSMakeRange(i,1) withString:@""];
}
}
return string;
}