NSString+NSMutableString+NSValue+NSAraay用法汇总
2010-09-16 23:54:00 来源:WEB开发网//快速枚举
//for(NSString *filename in direnum)
//{
// if([[filename pathExtension] isEqualToString:@"jpg"]){
// [files addObject:filename];
// }
//}
NSLog(@"files:%@",files);
//枚举
NSEnumerator *filenum;
filenum = [files objectEnumerator];
while (filename = [filenum nextObject]) {
NSLog(@"filename:%@",filename);
}
@"b",@"a",@"e",@"d",@"c",@"f",@"h",@"g",nil];
NSLog(@"oldArray:%@",oldArray);
NSEnumerator *enumerator;
enumerator = [oldArray objectEnumerator];
id obj;
while(obj = [enumerator nextObject])
{
[newArray addObject: obj];
}
[newArray sortUsingSelector:@selector(compare:)];
NSLog(@"newArray:%@", newArray);
[newArray release];
/*--------------------------- 切分数组------------------------------*/
//从字符串分割到数组- componentsSeparatedByString:
NSString *string = [[NSString alloc] initWithString:@"One,Two,Three,Four"];
NSLog(@"string:%@",string);
NSArray *array = [string componentsSeparatedByString:@","];
NSLog(@"array:%@",array);
[string release];
//从数组合并元素到字符串- componentsJoinedByString:
NSArray *array = [[NSArray alloc] initWithObjects:@"One",@"Two",@"Three",@"Four",nil];
NSString *string = [array componentsJoinedByString:@","];
NSLog(@"string:%@",string);
/************************************************************************
NSMutableArray
*************************************************************************/
/*--------------- 给数组分配容量----------------*/
//NSArray *array;
array = [NSMutableArray arrayWithCapacity:20];
/*-------------- 在数组末尾添加对象----------------*/
Tags:NSString NSMutableString NSValue
编辑录入:coldstar [复制链接] [打 印]更多精彩
赞助商链接