我正在解析一些 XML,其中包含格式为 100,000+
的数字作为 NSString。我想将这些值转换为我用它们计算的整数。既然有“,”和“+”,我该怎么做?
最佳答案
试试这段代码
NSMutableString* string = [NSMutableString stringWithString: @"100,000+"];
[string replaceOccurencesOfString: @"\," withString: @"" options: 0 range: NSMakeRange(0, [string length] ) ];
[string replaceOccurencesOfString: @"\+" withString: @"" options: 0 range: NSMakeRange(0, [string length] ) ];
NSInteger intValue = [string integerValue];
关于ios - 将 NSString 转换为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14460555/