美文网首页
string截取和拼接

string截取和拼接

作者: 哎呦我去叫什么呢 | 来源:发表于2016-08-04 14:57 被阅读35次

    NSString * string = @“11111111111”;

    NSString * str1 = [string substringToIndex:3];

    NSLog(@"%@",str1);

    专门截取字符串的一块从第3位开始,长度为4

    NSString * str2 = [string substringWithRange:NSMakeRange(3, 4)];

    NSLog(@"%@",str2);

    从第七位开始带结束

    NSString * str3 = [string substringFromIndex:7];

    NSLog(@"%@",str3);

    string = [NSString stringWithFormat:@"%@-%@-%@",str1,str2,str3];

    NSString *tempA = @"123";

    NSString *tempB = @"456";

    1,字符串拼接

    NSString *newString = [NSString stringWithFormat:@"%@%@",tempA,tempB];

    2,字符转int

    int intString = [newString intValue];

    3,int转字符

    NSString *stringInt = [NSString stringWithFormat:@"%d",intString];

    4,字符转float

    float floatString = [newString floatValue];

    5,float转字符

    NSString *stringFloat = [NSString stringWithFormat:@"%f",intString];

    将string字符串转换为array数组

    NSArray  *array = [Str componentsSeparatedByString:@","];

    ==反向方法

    将array数组转换为string字符串

    NSString *tempString = [mutableArray componentsJoinedByString:@","];--分隔符

    相关文章

      网友评论

          本文标题:string截取和拼接

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