ios - 将 NSString 转换为整数

标签 ios objective-c parsing

我正在解析一些 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/

相关文章:

powershell - 在 powershell 中解析结构化文件 (FIX 4.4)

ios - 检查数据库值是否大于 Firebase 中的本地值

iphone - AVFoundation AVPlayereekToTimecompletionHandler语法

json - 使用 Swift 可解码解析 JSON 字典时出错

python - 我如何解析这种类型的表达式?

ios - 在 iOS 中检查互联网连接的最新有效方法是什么?

ios - 从模态呈现的 View Controller 传回数据的委托(delegate)

ios - 如何在 iOS 中将数据从容器发送到父 View Controller ?

ios - 使用未声明的标识符 'startCameraControllerFromViewController'

iphone - UITextView 格线背景但错误的行高