views:

172

answers:

3

I m the beginner in iphone Thanks for sending me answer.... I want to break following NSMutable string into substring

200,8,"7 Infinite Loop, Cupertino, CA 95014, USA"

I wanting only Cupertino and CA from above Mutable String. can it is possible in iphone in objective-C The above data is the mutable data, which is came from httprequest object. I want to fetching the city and state name from above same kind og mutable strings. please give me the solution it creating a lot of hedac for me.

+2  A: 

If this is CSV data, check out

http://www.macresearch.org/cocoa-scientists-part-xxvi-parsing-csv-data

St3fan
+1  A: 

One method would be to split the string at commas and trim whitespace:

NSArray *substrings = [myString componentsSeparatedByString: @","];
NSCharacterSet *whitespace = [NSCharacterSet whitespaceCharacterSet];
NSMutableArray *result = [NSMutableArray array];
for ( NSString *str in substrings )
    [result addObject: [str stringByTrimmingCharactersInSet: whitespace]];
Costique
A: 

Are all of the strings that you want to break apart in this format?

NSArray *myArray = [string componentsSeparatedByString:@","];
NSString * strippedNumbers = [[myArray objectAtIndex:4] stringByReplacingOccurrencesOfRegex:@"[^0-9]" withString:@""];
NSString *myString = [NSString stringWithFormat:@"%@ %@", [myArray objectAtIndex:3], strippedNumbers];
Jack
Thanks its too much helful for me.
RRB