Separate NSString with a comma

I have a JSON channel connected to my application. One of the elements is lat and long, separated by a comma. For example: "32.0235, 1.345".

I am trying to break this down into two separate values, separating them with a comma.

Any tips? Thank!!

+46
json iphone nsstring comma
Jun 22 '11 at 16:50
source share
5 answers
NSArray *strings = [coords componentsSeparatedByString:@","]; 
+128
Jun 22 '11 at 16:53
source share
 NSString* myString = @"32.0235, 1.345". NSArray* myArray = [myString componentsSeparatedByString:@","]; NSString* firstString = [myArray objectAtIndex:0]; NSString* secondString = [myArray objectAtIndex:1]; 

See documentation

+16
Jun 22 '11 at 16:57
source share

Do you want to:

- (NSArray *)componentsSeparatedByString:(NSString *)separator

using @ "," as a delimiter.

+5
Jun 22 '11 at 16:53
source share

This is work for me, as I have not looked for a definition of any array.

 NSString* firstString = [[myString componentsSeparatedByString:@","] objectAtIndex:0]; 
+2
Jan 20 '14 at 0:12
source share

Try [yourCommaSeparatedString componentsSeparatedByString:@", "]
which will give NSArray with strings, you can then call floatValue on;)

+1
Jun 22 '11 at 16:56
source share



All Articles