xcode 将 NSString 拆分为其他 NSString

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8256080/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:32:19  来源:igfitidea点击:

xcode split NSString to other NSStrings

xcodensstringsplit

提问by Babis Papadopoulos

{"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

我用 nsstring 获取这些数据,我的问题是如何拆分数据,将其分隔为另一个 nsstrings,但我想将 nsstrings 设为逗号

回答by Minakshi

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
}

回答by Tendulkar

    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).