iOS之字符串与数组相互转换

NSString *string = @"www.qiyuan.jiuqi.com";
//将字符串按指定字符分割成数组
NSArray *array = [string componentsSeparatedByString:@"."];
//数组倒序
NSArray *resultArray = [[array reverseObjectEnumerator] allObjects];
//将数组用指定字符拼接成字符串
NSString *resultString = [resultArray componentsJoinedByString:@"/"];

NSLog(@"1-%@", string);
NSLog(@"2-%@", array);
NSLog(@"3-%@", resultArray);
NSLog(@"4-%@", resultString);

打印结果:

1-www.qiyuan.jiuqi.com
2-(www,qiyuan,jiuqi,com)
3-(com,jiuqi,qiyuan,www)
4-com/jiuqi/qiyuan/www

你可能感兴趣的:(iOS之字符串与数组相互转换)