Objective C: Get Substring between Double Quotes
ios, nsstring, objective-c, substring, xcode
Solution
This should get you started:
NSString *str = @"abcd \"efgh\" ijklm \"no\" p \"qrst\" uvwx \"y\" z";
NSMutableArray *target = [NSMutableArray array];
NSScanner *scanner = [NSScanner scannerWithString:str];
NSString *tmp;
while ([scanner isAtEnd] == NO)
{
[scanner scanUpToString:@"\"" intoString:NULL];
[scanner scanString:@"\"" intoString:NULL];
[scanner scanUpToString:@"\"" intoString:&tmp];
if ([scanner isAtEnd] == NO)
[target addObject:tmp];
[scanner scanString:@"\"" intoString:NULL];
}
for (NSString *item in target)
{
NSLog(@"%@", item);
}
Problem
What would be the best way to get every substring between double quotes and make it into an array? For example, if the string (NSString) is: ``` @"abcd \"efgh\" ijklm \"no\" p \"qrst\" uvwx \"y\" z" ``` I want the result to be: ``` {@"efgh", @"no", @"qrst", @"y"} ``` as an NSArray.