xcode 如何从数组 iphone sdk 中删除特定对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3778012/
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
how to remove particular objects from array iphone sdk
提问by Pankaj Kainthla
i have an string of these words between irregular spaces
我在不规则空格之间有一串这些单词
"gbpjpy buy 132.00/15 131.95 update close at 132.40 close at 132.40 120+ gbpjpy buy 132.00/15 131.50 45 new 90 120+ gpbusd buy update HIT 40 PIPS HIT 110 PIPS gpbusd buy BREAK EVEN update HIT 100+ gpbusd buy 1.5500/25 1.5455 new 40 100+ gpbusd buy update CLOSE 0 TO 10 PIPS N gpbusd buy 1.5335/50 1.5320 new 40 80+ gpbusd buy update 15-20 PIPS CLOSE KEEP OPEN gpbusd buy 1.5530/50 1.5505 update HIT 80 KEEP OPEN gpbusd buy 1.5530/50 1.5465 new 40 80 100+"
In this string there are irregular spaces ?can anybody tell a proper way to remove those spaces ?
在这个字符串中有不规则的空格?有人能告诉一个正确的方法来删除这些空格吗?
回答by RolandasR
[yourArray removeObject:@"object"];
yourArray must be muttable
yourArray 必须是可变的
回答by Ajith
or you can do this also [yourArray removeObjectAtIndex:index];
look at the header files of NSArray
and NSMutableArray
.
或者你可以做到这一点也[yourArray removeObjectAtIndex:index];
看的头文件NSArray
和NSMutableArray
。
回答by Pankaj Kainthla
I myself found an answer may this will help othe rpeople too:My question code had irregular spaces between items, this will remove all spaces and store items in array
我自己找到了一个答案,这可能对其他人也有帮助:我的问题代码在项目之间有不规则的空格,这将删除所有空格并将项目存储在数组中
NSString *str=@"mango apple banana grapes pineapple";
NSRange match;
arr=[[NSMutableArray alloc]init];
while(str.length>0)
{
match = [str rangeOfString: @" "];
if(match.location>=str.length)
{
[arr addObject:str];
break;
}
NSString *str2=[str substringToIndex:match.location];
str=[str substringFromIndex:match.location+1];
if(str2.length==0)
{
continue;
}
[arr addObject:str2];
}
NSLog(@"array is %@",arr); //here is your array