2011-11-24 10 views
6
{"Title":"Chatroom","Year":"2010","Rated":"R","Released":"11 Aug 2010","Genre":"Drama, Thriller","Director":"Hideo Nakata","Writer":"Enda Walsh, Enda Walsh","Actors":"Aaron Johnson, Imogen Poots, Matthew Beard, Hannah Murray","Plot":"A group of teenagers encourage each other's bad behavior.","Poster":"http://ia.media-imdb.com/images/M/[email protected]@._V1._SX320.jpg","Runtime":"1 hr 37 mins","Rating":"5.3","Votes":"1000","ID":"tt1319704","Response":"True"} 

mogę dostać te dane z NSString i moje pytanie brzmi: w jaki sposób podzielić dane, które oddziela się kolejne nsstrings, ale chcę, aby jak przecinkami tyle nsstringsXcode podzielić NSString do innych NSStrings

+2

patrząc na te dane, myślę, że będziesz lepiej szuka parsera JSON, które powinny dać ci NSDictionary lub podobny do przechodzenia przez strukturę danych. –

+0

dane są poprawne, chcę tylko podzielić tekst pomiędzy, każdy na nsstring, nie wszystkie z nich na inne nsstring, może na tablicę, ale na wielowierszową tablicę, więc mogę używać wszystkiego oddzielnie –

Odpowiedz

14

użyć następujących

NSString *str; //Pass your string to str 
NSArray *array = [str componentsSeparatedByString:@","]; 

for(int i = 0; i < [array count]; i++) { 
    // Here just take strings one by one 
} 
+0

ok, dziękuję bardzo –

1
NSString *string= //pass the string whatever you want. 
    NSArray *splitArray = [string componentsSeparatedByString:@","]; //it separates the string and store it in the different different indexes. 

Ex: 
    NSString *str= @"one,two,three"; 
    NSArray *array = [str componentsSeparatedByString:@","]; //it separates the string and store it in the different different indexes(one is at index 0 ,two is at index 1 and three is at index 2). 
+0

dzięki za odpowiedź i jak mogę użyć indeksu tablicy? jak mogę skopiować indeks [1] do nsstring i etc? –

+0

NSString * secondString = [tablica objectAtIndex: 1]; – Tendulkar

+0

Jeśli to działa, zaakceptuj to jako odpowiedź ... – Minakshi