美文网首页
NSArray 转 NSString 转 NSArray,NSS

NSArray 转 NSString 转 NSArray,NSS

作者: CoderChou | 来源:发表于2017-04-05 09:55 被阅读734次
    NSArray *stringArray = @[@"甲",@"已",@"丙",@"丁"];
    NSString *arrrayString = [testArray componentsJoinedByString:@"-"];
    NSLog输出:arrrayString
    甲-已-丙-丁
    
    NSString *string = @"甲-已-丙-丁";
    NSArray  *stringArray = [string componentsSeparatedByString:@"-"];
    NSLog输出:stringArray
    (
        "\U7532",
        "\U5df2",
        "\U4e19",
        "\U4e01"
    )
    
    NSString*string =@"sdfsfsfsAdfsdf";
    string = [string substringToIndex:7];//截取掉下标7之后的字符串
    NSLog(@"截取的值为:%@",string);
    [string substringFromIndex:2];//截取掉下标2之前的字符串
    NSLog(@"截取的值为:%@",string);
    
    2.匹配字符串
    NSString*string =@"sdfsfsfsAdfsdf";
    NSRangerange = [stringrangeOfString:@"f"];//匹配得到的下标
    NSLog(@"rang:%@",NSStringFromRange(range));
    string = [string substringWithRange:range];//截取范围类的字符串
    NSLog(@"截取的值为:%@",string);
    
    3.分隔字符串
    NSString*string =@"sdfsfsfsAdfsdf";
    
    NSArray *array = [string componentsSeparatedByString:@"A"]; //从字符A中分隔成2个元素的数组
    NSLog(@"array:%@",array); //结果是adfsfsfs和dfsdf
    

    相关文章

      网友评论

          本文标题:NSArray 转 NSString 转 NSArray,NSS

          本文链接:https://www.haomeiwen.com/subject/wcstattx.html