(一)相互转换
1、字符转int
NSString *newString =@“xxx”; int intString = [newString intValue];
2、int转字符
NSString *stringInt = [NSString stringWithFormat:@"%d",intString];
3、字符转float
float floatString = [newString floatValue];
4、float转字符
NSString *stringFloat = [NSString stringWithFormat:@"%f",intString];
(二)字符串拼接
NSString* string; // 结果字符串 NSString* string1, string2; //已存在的字符串,需要将string1和string2连接起来 //方法1. string = [NSString initWithFormat:@"%@,%@", string1, string2 ]; //方法2. string = [string1 stringByAppendingString:string2]; //方法3 . string = [string stringByAppendingFormat:@"%@,%@",string1, string2];
时间: 2024-11-09 02:17:41