2011-11-24 6 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"} 

मैं NSString के साथ इस डेटा प्राप्त करने NSString विभाजित है और मेरे सवाल का डेटा है कि, एक और nsstrings को अलग करती है विभाजित करने के लिए कैसे है, लेकिन मैं अल्पविराम का इतना nsstringsxcode अन्य NSStrings

+2

कि डेटा मुझे लगता है कि आप एक JSON पार्सर, जो आप एक NSDictionary या इसी तरह के डेटा संरचना traversing के लिए देना चाहिए की तलाश में बेहतर होगा पर देख रहे हैं। –

+0

डेटा सही है, मैं सिर्फ सभी को एक एनएसस्ट्रिंग के बीच पाठ को विभाजित करना चाहता हूं, न कि उन सभी को एक अन्य एनएसस्ट्रिंग के लिए, शायद एक सरणी लेकिन मल्टीलाइन सरणी में ताकि मैं अलग-अलग –

उत्तर

14

उपयोग के रूप में बनाना चाहते निम्नलिखित

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

ठीक से उपयोग कर सकूं, धन्यवाद –

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

धन्यवाद उत्तर और मैं सरणी के सूचकांक का उपयोग कैसे कर सकता हूं? मैं सूचकांक [1] को nsstring और आदि में कैसे कॉपी कर सकता हूं? –

+0

एनएसएसटींग * सेकंडस्ट्रिंग = [सरणी ऑब्जेक्टएंड इंडेक्स: 1]; – Tendulkar

+0

यदि यह आपके लिए काम किया गया है तो इसे उत्तर के रूप में स्वीकार करें ... – Minakshi