objective-c - 如何在Objective C中将基于XML的字符串值转换为整数

标签 objective-c ios xcode4.2 xcode4.3

这是用逗号分隔的 XML 代码,我将其解析为字符串,现在需要转换为整数:
.h 文件中的结构:
NSString * 位置;

XML 文件:
100,280,924,320

这是代码:

 NSArray * positons = [partyMember elementsForName:@"position"];
    if (positons.count > 0) {
        GDataXMLElement *firstName = (GDataXMLElement *) [positons objectAtIndex:0];
        //parsed[i].positons = firstName.stringValue;
        parsed[i].positons = firstName.stringValue;
        NSLog(@"position-%@,\n",parsed[i].positons);

名字是本地声明的, parsed[i].positions 具有 da 解析值,

最佳答案

您可以使用以下方法获取字符串数组:

NSArray* arr = [fullStr componentsSeparatedByString:@","] 

然后从中得到一个 int
int firstInt = [[arr objectAtIndex:0] intValue]; 

关于objective-c - 如何在Objective C中将基于XML的字符串值转换为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13414579/

相关文章:

objective-c - 创建信号信号以组合信号并在完成或错误时完成的首选方法是什么?

java - 如何在Android中显示此通知?

ios - 呈现弹出 View 时,如何让用户选择父 Collection View 中的单元格?

iphone - 无法控制 UITextView 的宽度

ios - 在 Objective-C 中设置日期格式

objective-c - 同时动画旋转/缩放/平移 UIImage

ios - 旋转 UIBezierPath 矩形

iphone - Xcode 4.2 模拟器崩溃日志

ios - 在 iOS 中使用多个 Storyboard

objective-c - 匹配字符串中短语的第一个单词