这是用逗号分隔的 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/