3

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?

4

1 回答 1

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

这将摆脱引号。将此与我的评论结合起来,您就已经弄清楚了。

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

如果;不是char您需要拆分的,您需要将其更改为char您需要拆分的。如果您需要拆分多个分隔符,那么您需要查看该componentsSeparatedByCharactersInSet方法。

于 2013-10-31T02:12:31.193 回答