Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS split string [closed]

ex1) a:3:{i:0;s:6:"Apple";i:1;s:4:"Google";}

ex2) a:2:{i:0;s:13:"Area";i:1;s:10:"Place";i:2;s:10:"Location";}

ex3) a:4:{i:0;s:6:"Cool";i:1;s:6:"Nice";i:2;s:6:"Awesome";i:3;s:6:"Wonderful";}

ex4) ...

ex5) ...

this is Answers about our Survey. i received string from server to iPhone. something like that.

a:%d is words count about answer.

i:%d is Index about words. it is increase.

s:%d is length about word.

i don't know what will be word inside double quotation marks. (random)

i understood componentsSeparatedByString. how to get words inside double quotation marks?

like image 292
Lee Avatar asked May 12 '26 08:05

Lee


1 Answers

[str stringByReplacingOccurrencesOfString:@"\"" withString:@""];

This will get rid of the quotes. Combine this with my comment and you've got it all figured out.

NSMutableArray *arrSplitString = [NSMutableArray arrayWithArray:[originalString componentsSeperatedByString:@";"]];
for(int i=0; i<[arrSplitString count]; ++i) {
    arrSplitString[i] = [arrSplitString[i] stringByReplacingOccurrencesOfString:@"\"" withString:@""];
}

If the ; isn't the char you need to split on, you'll need to change that to the char you need to split on. If you need to split on multiple delimiters, then you'll want to look at the componentsSeparatedByCharactersInSet method.

like image 144
nhgrif Avatar answered May 13 '26 22:05

nhgrif



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!