// insert code here...數組
NSLog(@"數組");spa
//指定多個字符串建立數組code
NSArray *array;對象
array=[NSArrayarrayWithObjects:@"0-asd",@"1-fds",@"2-哈咯",@"3-我的",nil];索引
//數組的長度rem
NSLog(@"數組長度%d",array.count);字符串
//經過索引取得對象string
for(int i=0;i<array.count;i++)it
{table
NSString *secondStr=[array objectAtIndex:i];
NSLog(secondStr,nil);
}
//高速枚舉法取得對象,Objective-C2.0開始支持,
for(NSString *str in array)
{
NSLog(str,nil);
}
//對象的追加於刪除
//建立空數組
NSMutableArray *MutArray=[NSMutableArray array];
//追加對象
[MutArray addObject:@"A"];
[MutArray addObjectsFromArray:array];
//插入對象
NSString *thstr=@"插入值";
[MutArray insertObject:thstr atIndex:4];
//替換對象
[MutArray replaceObjectAtIndex:2 withObject:@"替換"];
//刪除全部對象
//[Mutarray removeAllObjects];
//刪除最後的對象
[MutArray removeLastObject];
//刪除索引爲Index的對象
[MutArray removeObjectAtIndex:0];
//刪除全部於object同值的對象
[MutArray removeObject:@"0-asd"];
//刪除數組中全部與object等價的對象
[MutArray removeObjectIdenticalTo:thstr];
//刪除數組中全部與數組array包含相同的元素
[MutArray removeObjectsInArray:array];
NSLog(@"%@",MutArray);
/*添加對象到數組中,若是數組中已有該字符串,則不添加到數組*/
-(void)TestTheStringhaveOrNotHave:(NSMutableArray*)array string:(NSString*)str
{
// for (int i = 0; i<[antherarray count]; i++)
// {
// NSString * str = [antherarray objectAtIndex:i];
[array addObject:str];
NSIntegerindex= [array indexOfObject:str inRange:NSMakeRange(0, [array count] - 1)];
if(index!= NSNotFound)
{
[array removeObjectAtIndex:index];
}
// }
}
/*刪除數組中已經添加相同人名*/
-(void)DeleateTheNotSelectString:(NSMutableArray*)array string:(NSString*)Delstr
{
if([array count]> 0)
{
[array removeObjectIdenticalTo:Delstr];
}
}