轉換NSString到Int類型,得到dpPoint:0
。而我需要的結果是dpPoint:2
。
dpPointStr = [NSString stringWithFormat:@"%@",[verifyRow valueForKey:@"default_point"]];
NSLog(@"dpPointStr:%@",dpPointStr); //Result dpPointStr:2
int dpPoint = [dpPointStr intValue];
NSLog(@"dpPoint:%i",dpPoint); //Result dpPoint:0
如果值在字符串的開始或結尾處,可以這樣試試:
int val = [[dpPointStr stringByTrimmingCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]] intValue];