问题描述
- 转换NSString到Int类型
- 转换NSString到Int类型,得到
dpPoint:0
。而我需要的结果是dpPoint:2
。dpPointStr = [NSString stringWithFormat:@""%@""[verifyRow valueForKey:@""default_point""]];NSLog(@""dpPointStr:%@""dpPointStr); //Result dpPointStr:2int dpPoint = [dpPointStr intValue];NSLog(@""dpPoint:%i""dpPoint); //Result dpPoint:0
解决方案
如果值在字符串的开始或结尾处,可以这样试试:
int val = [[dpPointStr stringByTrimmingCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]] intValue];
解决方案二:
最简单的方法是:
int dpPoint = [[verifyRow valueForKey:@""default_point""] intValue];
时间: 2024-12-11 19:33:44