gpt4 book ai didi

ios - 如何分离NSMutablearray中存在的元素

转载 作者:行者123 更新时间:2023-12-01 16:44:05 25 4
gpt4 key购买 nike

我有一个带有NSMutablearray的应用程序,显示如下,我想要另一个数组,它包含一个接一个的所有城市,并且没有城市。到目前为止,索引1处的对象显示:

 2014-02-07 18:41:15.567 [313:a0b] cities Array (
"Bangalore",
"Chennai",
"Delhi",
"Mumbai"
)

我希望将其分隔为:
Bangalore
Chennai
Delhi
Mumbai
Pune with out NO CITY


2014-02-07 18:41:15.567 [313:a0b] cities Array NO CITY
2014-02-07 18:41:15.567 [313:a0b] cities Array (
"Bangalore",
"Chennai",
"Delhi",
"Mumbai"
)
2014-02-07 18:41:15.567 [313:a0b] functionalities Array NO CITY
2014-02-07 18:41:15.568 [313:a0b] functionalities Array Pune

最佳答案

请找到解决方案:

    NSMutableArray *arr = [[NSMutableArray alloc] initWithObjects:@"Bangalore",@"Chennai", @"Delhi", @"Pune", nil];
NSLog(@"%@", [arr description]);

NSMutableArray *arr1 = [[NSMutableArray alloc] init];

for (NSString *str in arr) {
if (![str isEqualToString:@"Pune"]) {
[arr1 insertObject:str atIndex:arr1.count];
}
}
NSLog(@"%@", [arr1 description]);

如果要在同一数组中执行操作,请使用以下代码:
    NSMutableArray *arr = [[NSMutableArray alloc] init];
[arr addObject:@"Banagalore"];
[arr addObject:@"Delhi"];
[arr addObject:@"Mumbai"];
[arr addObject:@"Pune"];

NSLog(@"%@", [arr description]);

for (int i = 0; i <[arr count] ; i++ )
{
if ([[arr objectAtIndex:i] isEqualToString:@"Pune"]) {
[arr removeObjectAtIndex:i];
}
}
NSLog(@"%@", [arr description]);

关于ios - 如何分离NSMutablearray中存在的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21629122/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com