2 daffodilgirl DaffodilGirl 于 2012.12.05 13:34 提问

MutableArray怎么复制最后三个字符?

怎么样把MutableArray中的最后三个字符复制到另外的MutableArray中?

 MutableArray1:(
           "22.298166 , 73.165809",
           "22.300598 , 73.167183",
           "22.298101 , 73.166188",
           "22.298128 , 73.166194"
           "22.298130 , 73.166194"
          )

O(∩_∩)O谢谢

3个回答

g989_1314125
g989_1314125   2012.12.05 16:58
已采纳

用NSArray的subarrayWithRange:

NSRange range = NSMakeRange([mutableArray1 count] - 3, 3);
NSMutableArray *mutableArray2 = [NSMutableArray arrayWithArray:
                                  [mutableArray1 subarrayWithRange:range]];
Chengzi_963
Chengzi_963   2012.12.05 14:22

用循环:

int i=1;
while (i<4 && i < [array1 count])
{
    [array2 addObject:[array1 objectAtIndex:([array1 count]-i)]];
    i++;
}
redCoral_
redCoral_   2012.12.05 17:09

试试:

NSMutableArray * array = [[NSMutableArray alloc]initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8", nil];

    NSMutableArray * otherArray = [[NSMutableArray alloc]init];
    for (int i= array.count-3; i<array.count; i++) {
        [otherArray addObject:[array objectAtIndex:i]];
    }
    NSLog(@"%@",otherArray);
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!