Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xcode split NSString to other NSStrings

{"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/MV5BMjE0MjM5MDM2MF5BMl5BanBnXkFtZTcwMzg1MzY0Mw@@._V1._SX320.jpg","Runtime":"1 hr 37 mins","Rating":"5.3","Votes":"1000","ID":"tt1319704","Response":"True"}

i get this data with nsstring and my question is how to split data that , separates to another nsstrings, but i want to make as commas so much nsstrings

like image 390
Babis Papadopoulos Avatar asked Nov 24 '11 11:11

Babis Papadopoulos


2 Answers

Use the following

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
}
like image 150
Minakshi Avatar answered Nov 15 '22 06:11

Minakshi


    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).
like image 35
Tendulkar Avatar answered Nov 15 '22 07:11

Tendulkar