- #import <Foundation/Foundation.h>
- int main(int argc, const char * argv[]) {
- @autoreleasepool {
- //把数组元素链接成字符串
- NSArray *arr=@[@"l",@"a",@"z",@"y",@"l",@"o",@"v",@"e",@"3",@"3"];
- //-(NSString *)componentsJoinedByString:(NSString *)separator;
- //用seperator作为拼接符把数组中的元素拼接起来
- NSString *str=[arr componentsJoinedByString:@""];
- NSLog(@"%@",str);
- //把一个字符串分割,存放在数组中,数组必须有一定规律
- NSString *str1=@"400-800-12580";
- NSArray *arr1=[str1 componentsSeparatedByString:@"-"];
- [arr1 enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- NSLog(@"idx=%lu,obj=%@",idx,obj);
- }];
- }
- return 0;
- }
复制代码 |
|