问题
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