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

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

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

上一篇:虾米loop 摇头代码


下一篇:JS 实现的年月日三级联动