I have NSString's
in the form of Johnny likes "eating" apples
. I want to remove the quotations from my strings so that.
Johnny likes "eating" apples
becomes
John likes apples
I've been playing with NSScanner to do the trick but I'm getting some crashes.
- (NSString*)clean:(NSString*) _string
{
NSString *string = nil;
NSScanner *scanner = [NSScanner scannerWithString:_string];
while ([scanner isAtEnd] == NO)
{
[scanner scanUpToString:@"\"" intoString:&string];
[scanner scanUpToString:@"\"" intoString:nil];
[scanner scanUpToString:@"." intoString:&string]; // picked . becuase it's not in the string, really just want rest of string scanned
}
return string;
}
This code is hacky, but seems to produce the output you want.
It was not tested with unexpected inputs (string not in the form described, nil string...), but should get you started.
I will come back (much) later to clean it, and drill into the documentation of the class NSScanner to figure what I am missing, and had to take care with a manual string trimming.