【编程技巧】一些 NSArray 的基本操作代码例子

时间:2022-07-22 13:53:42

/*---------------------------切分数组------------------------------*/

//从字符串分割到数组- 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);

其余的见:http://www.cocoachina.com/newbie/tutorial/2010/1009/2151.html