string截取和拼接

2016-08-04  本文已影响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:@","];--分隔符

上一篇下一篇

猜你喜欢

热点阅读