【编程技巧】一些 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

 

 

posted @ 2013-08-12 17:15  ejllen  阅读(153)  评论(0编辑  收藏  举报