Objective c 如何在Objective C中将基于XML的字符串值转换为整数
这是用逗号分隔的XML代码,我将其解析为字符串,现在需要转换为整数: .h文件中的结构: NSString*位置 XML文件: 100280924320 代码如下:Objective c 如何在Objective C中将基于XML的字符串值转换为整数,objective-c,ios,xcode4.2,xcode4.3,Objective C,Ios,Xcode4.2,Xcode4.3,这是用逗号分隔的XML代码,我将其解析为字符串,现在需要转换为整数: .h文件中的结构: NSString*位置 XML文件: 100280924320 代码如下: NSArray * positons = [partyMember elementsForName:@"position"]; if (positons.count > 0) { GDataXMLElement *firstName = (GDataXMLElement *) [positons ob
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);
名字在本地声明,已解析[i]。位置具有da解析值,您可以通过以下方式将NSString更改为int值:
[string intValue];
[string floatValue];
但这只有在值为数字但为字符串形式时才有意义,您可以通过以下方式将NSString更改为int值:
[string intValue];
[string floatValue];
但这只有在值为数字但为字符串形式时才有意义,您可以使用以下方法获得字符串数组:
NSArray* arr = [fullStr componentsSeparatedByString:@","]
然后从中得到一个int
int firstInt = [[arr objectAtIndex:0] intValue];
可以使用以下命令获取字符串数组:
NSArray* arr = [fullStr componentsSeparatedByString:@","]
然后从中得到一个int
int firstInt = [[arr objectAtIndex:0] intValue];
可以使用以下代码从字符串中获取整数值: 首先在任何数组中获取逗号分隔的对象,如下所示:
NSArray *arrObjects=[parsed[i].positons componentsSeparatedByString:@","];
然后使用该数组将字符串值转换为整数,如下所示:
int iFirstValue=[[arrObjects objectAtIndex:0] intValue];
其他类似。您可以使用以下代码从字符串中获取整数值: 首先在任何数组中获取逗号分隔的对象,如下所示:
NSArray *arrObjects=[parsed[i].positons componentsSeparatedByString:@","];
然后使用该数组将字符串值转换为整数,如下所示:
int iFirstValue=[[arrObjects objectAtIndex:0] intValue];
其他人也一样。以下是我所做的:在viewcontroller中应用Objectatindex值时更改它
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(@" parsed position is %d, i = %d\n",[parsed[i].positons integerValue],i);
NSArray* arr = [parsed[i].positons componentsSeparatedByString:@","];
// firstStr = [[arr objectAtIndex:0] intValue];
NSLog(@"position-%d,\n",[[arr objectAtIndex:2] intValue]);
下面是我所做的:在viewcontroller中应用Objectatindex值时更改它
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(@" parsed position is %d, i = %d\n",[parsed[i].positons integerValue],i);
NSArray* arr = [parsed[i].positons componentsSeparatedByString:@","];
// firstStr = [[arr objectAtIndex:0] intValue];
NSLog(@"position-%d,\n",[[arr objectAtIndex:2] intValue]);
nslog打印什么?是不是像这个位置-100位置-280位置-924现在只打印第一个位置i,e 100 nslog打印什么?是不是像这个位置-100位置-280位置-924现在它只打印第一个位置,即100@daveGot非常感谢!!:@达维戈:非常感谢!!:@佩德罗,@svrushal这正是我所做的!!:谢谢guys@Dr.Droid:我只是稍微改进了答案的格式。所有的赞美都应该归于@svrushal!如果你喜欢这个答案,你也可以投票,除了接受它。@Pedro,@svrushal这正是我所做的!!:谢谢guys@Dr.Droid:我只是稍微改进了答案的格式。所有的赞美都应该归于@svrushal!如果你喜欢答案,除了接受它之外,你还可以投上一票。