如何将NSMutableArray值转换为NSString?

时间:2012-01-09 11:12:30

标签: iphone ios4

大家知道如何将NSMutableArray值转换为NSString  当我这样做时

Webservices *details=[[Webservices alloc] init];
[details getMobileNumberDetails:phnotextfield.text];

NSLog(@"longitudes Arrays from %@",details.resultData);
  

“ - 91.57696007”,       “10.343234”       “74.982343”       “76.464844”       “76.464844”       “2.256”,

但是当像这样实施时

theCoordinate2.longitude = [[details.longarray objectAtIndex:0] floatValue];
NSLog(@"longitudes list from %@",theCoordinate2.longitude);
  

-91.57696007

但我的目的是将所有值分配给theCoordinate2.longitude,以便帮助我存储到iphone中的字符串元素中。

2 个答案:

答案 0 :(得分:3)

您可以使用此代码:

theCoordinate2.longitude = [[details.longarray objectAtIndex:0] stringByAppendingString:[details.longarray objectAtIndex:1];
//and so on for index 2,3,4   stringByAppendingString:[details.longarray objectAtIndex:2

NSLog(@"longitudes list from %f",theCoordinate2.longitude);

答案 1 :(得分:1)

+1给Wasif,但在他撰写答案的时候,我正在编写我自己的代码版本,你可以尝试:

NSMutableArray * longitudeArray = NULL;
NSString * detailsAsString = details.resultData;
if(detailsAsString)
{
    NSArray * longitudeStringArray = [detailsAsString componentsSeparatedByString, @","];
    if(longitudeStringArray && ([longitudeStringArray count] > 0))
    {
        longitudeArray = [[NSMutableArray alloc] initWithCapacity: [longitudeStringArray count]];
        if(longitudeArray)
        {
            for(NSString * longitudeString in longitudeStringArray)
            {
                [longitudeArray addObject: [NSNumber numberWithFloat: [longitudeString floatValue]]];
            }
        }

    } else {
        NSLog( @"did not extract an array out of webservice data");
    }
}