I like to copy the array A elements to Array B elements with specific
我喜欢将数组A元素复制到具有特定的Array B元素
example :
array A=[0123]
array b=[1111111111111111111]
i want `b=[1111111101231111111]
我想要`b = [1111111101231111111]
int ip=0;
[b addObjectsFromArray:[A objectsAtIndexes:[NSIndexSetindexSetWithIndexesInRange:NSMakeRange(ip, 10)]]];
i know how to copy the array element , i want to know how to replace the object start from 9 to 13 in array b to replaced by array a element , can any give me hint
我知道如何复制数组元素,我想知道如何替换对象从数组b中的9到13开始替换为数组元素,可以任何给我提示
2 个解决方案
#1
3
NSArray *a = @[@0,@1,@2,@3];
NSArray *b = @[@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1];
NSMutableArray *c = [b mutableCopy];
// The range here is index->8 (9th object) and length->4
[c replaceObjectsInRange:NSMakeRange(8,4) withObjectsFromArray:a];
#2
0
You need to create mutable copy of your array and modify them:
您需要创建数组的可变副本并进行修改:
NSMutableArray* mutableArray = [yourArray mutableCopy];
Then you will access to this methods: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html
然后您将访问以下方法:https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html
#1
3
NSArray *a = @[@0,@1,@2,@3];
NSArray *b = @[@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1,@1];
NSMutableArray *c = [b mutableCopy];
// The range here is index->8 (9th object) and length->4
[c replaceObjectsInRange:NSMakeRange(8,4) withObjectsFromArray:a];
#2
0
You need to create mutable copy of your array and modify them:
您需要创建数组的可变副本并进行修改:
NSMutableArray* mutableArray = [yourArray mutableCopy];
Then you will access to this methods: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html
然后您将访问以下方法:https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html