[英]how to remove brackets from NSarray
i have an array where i am trying to remove the brackets from the nsarray 我有一个数组,我正在尝试从nsarray删除括号
This is my output ( ( "2013-06-15 02:00" ), ( "2013-06-16 02:00" ), ( "2013-06-18 02:00" ), ( "2013-06-19 02:00" ), ( "2013-06-19 02:00" ) ) 这是我的输出((“ 2013-06-15 02:00”),(“ 2013-06-16 02:00”),(“ 2013-06-18 02:00”),(“ 2013-06- 19 02:00“),(” 2013-06-19 02:00“))
but i want to remove inner brackets and output as ( "2013-06-15 02:00", "2013-06-16 02:00", "2013-06-18 02:00", "2013-06-19 02:00", "2013-06-19 02:00" ) 但我想删除内括号并输出为(“ 2013-06-15 02:00”,“ 2013-06-16 02:00”,“ 2013-06-18 02:00”,“ 2013-06-19 02:00“,” 2013-06-19 02:00“)
Any one Please help me out to solve this issue 任何人请帮我解决这个问题
I'm answering to consider that this is an Simple NSArray
- 我回答是因为这是一个简单的NSArray
Your array is like this - 您的数组是这样的-
NSArray *array = @[@[@"2013-06-15 02:00"], @[@"2013-06-16 02:00"], @[@"2013-06-18 02:00"], @[@"2013-06-19 02:00"], @[@"2013-06-19 02:00"]];
NSLog(@"\n%@",array);
And then output of this array is:- 然后此数组的输出是:
( ( "2013-06-15 02:00" ), ( "2013-06-16 02:00" ), ( "2013-06-18 02:00" ), ( "2013-06-19 02:00" ), ( "2013-06-19 02:00" ) ) ((“ 2013-06-15 02:00”),(“ 2013-06-16 02:00”),(“ 2013-06-18 02:00”),(“ 2013-06-19 02:00 “),(” 2013-06-19 02:00“))
Now lets filter this array - 现在让我们过滤该数组-
NSMutableArray *newArray = [[NSMutableArray alloc] init];
for(int i=0; i<[array count]; i++)
{
[newArray addObject:array[i][0]];
}
NSLog(@"\n%@", newArray);
Output is:- ( "2013-06-15 02:00", "2013-06-16 02:00", "2013-06-18 02:00", "2013-06-19 02:00", "2013-06-19 02:00" ) 输出为:-(“ 2013-06-15 02:00”,“ 2013-06-16 02:00”,“ 2013-06-18 02:00”,“ 2013-06-19 02:00”,“ 2013-06-19 02:00“)
Use objectAtIndex as below: 使用objectAtIndex如下:
[yourArray objectAtIndex:i]
where i represents index,if you want first string then use 0,second then 1,....etc. 在这里我代表索引,如果你想第一个字符串然后使用0,second然后1,....等等。
Hope this might help you. 希望这对您有帮助。
Since I'm in a canihazecode-mood: 由于我处于canihazecode情绪中:
NSArray *array = ...
NSMutableArray *cleanedArray = [NSMutableArray arrayWithCapacity:[array count]];
for (id object in array) {
if ([object isKindOfClass:[NSArray class]]) {
if ([object count]) {
[cleanedArray addObject:object[0]];
}
else {
// empty array
}
}
else if ([object isKindOfClass:[NSString class]]) {
NSRange openBracket = [object rangeOfString:@"("];
NSString *temp = [object stringByReplacingCharactersInRange:openBracket withString:@""];
NSRange closeBracket = [temp rangeOfString:@")" options:NSBackwardsSearch];
temp = [temp stringByReplacingCharactersInRange:closeBracket withString:@""];
[cleanedArray addObject:temp];
}
else {
// unknown class
}
}
you might want to figure out if your objects are strings or arrays, and remove the superfluous part. 您可能想弄清楚对象是字符串还是数组,然后删除多余的部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.