I need to split up a string which is separated by commas while preserving any quoted substrings (which may have commas too).
String example:
NSString *str = @"One,Two,\"This is part three, I think\",Four";
for (id item in [str componentsSeparatedByString:@","])
NSLog(@"%@", item);
This returns:
- One
- Two
- "This is part three
- I think"
- Four
The correct result (respecting quoted substrings) should be:
- One
- Two
- "This is part three, I think"
- Four
Is there a reasonable way to do this, without re-inventing or re-writing quote-aware parsing routines?