I need to parse the following string in Objective-C for iOS app
NSString *htmlString = @”12, 22, ‘stringA’,”, ‘stringB, stringC’, 2,’stringD'”;
I would like to an array like this
{
@12,
@22,
@"stringA",
@"emptySlotInfo",
@"stringB, stringC",
@2,
@"stringD"
}
The headache is @”strinb, stringC” because
[htmlString componentsSeparatedByString:@","];
does not work for the case and the @”‘” as separator does not work either.
How can I get necessary components?
You could use NSScanner.
If it scans a
', it knows a string is starting and ignore,till it reads the next'. if no opening'was read, sperate by,.This cocoawithlove article might be helpful.
I made a quick prototype. Most likely there is much to optimize, as I am also not a expert for NSScanner
The resultArray contains