how to converts NSMutableArray values into NSString? [duplicate]

时光毁灭记忆、已成空白 提交于 2020-01-03 06:42:09

问题


hi all how to convert NSMutableArray values into the NSString when i did as like

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",

but when implemented like this

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

-91.57696007

but my intention is to assign all values to theCoordinate2.longitude so help me to store into string element in iphone.


回答1:


You can use this code:

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);



回答2:


+1 to Wasif, but while he was composing his answer I was composing my own version of the code you could try:

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");
    }
}


来源:https://stackoverflow.com/questions/8787505/how-to-converts-nsmutablearray-values-into-nsstring

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!