NSString 与 NSArray 的相互转换

//

//  main.m

//  NSArray NSString

//

//  Created by apple on 15/9/18.

//  Copyright (c) 2015 apple. All rights reserved.

//


#import


int main1(int argc, const char * argv[]) {

    @autoreleasepool {

//1,将数组元素连接成字符串

    NSArray *arr=@[@"敏感词",@"社团",@"和谐"];

        NSString *str=[arr componentsJoinedByString:@"|"];

        NSLog(@"str = %@",str);

       }

    return 0;

}

int main(int argc, const char * argv[]) {

    @autoreleasepool {

//2,将字符串拆成数组

// -(NSArray *)componentsSeparatedByString:(NSString *)separator;

        NSArray *arr = [@"1,2,3,4,5,6,7,8" componentsSeparatedByString:@","];

        NSLog(@"%@",arr);

            }

    return 0;

}


你可能感兴趣的:(NSString 与 NSArray 的相互转换)