objectc:nsstring和int、float互转,字符串拼接

1,字符串拼接

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

如果涉及到空字符串

NSString *tempA = @"123";
NSMutableString *printStr1 = [[NSMutableString alloc] init];//不要用@“”或者nil
 [printStr1 appendFormat:@"%@,",tempA];//刚开始的空字符可以通过这样实现覆盖

2,字符转int

 int i = [newString intValue];

3,int转字符

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

4,字符转float

float floatString = [newString floatValue];

5,float转字符

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

你可能感兴趣的:(工具)