views:

47

answers:

2

I was written an http request in objective-C i got reply from this method are 200,8,"7 Infinite Loop, Cupertino, CA 95014, USA" I want to catch Cupertino, CA words from it. Therefore i was written:

NSArray *myArray = [result5 componentsSeparatedByString:@","];
NSLog(@"Response: %@", myArray);
NSString * state = [[myArray objectAtIndex:4]
               stringByReplacingOccurrencesOfRegex:@"[^0-9]" withString:@""];
NSLog(@"Response9: %@", state);
NSString *city = [NSString stringWithFormat:@"%@ %@", 
                           [myArray objectAtIndex:3], state];
NSLog(@"Response1: %@", city);

But i got worning on the sentence of

NSString * state = [[myArray objectAtIndex:4]
             stringByReplacingOccurrencesOfRegex:@"[^0-9]" withString:@""];

which is "no -stringByReplacingOccurrenceoOfRegexwithString method found" and "Message without a matching method signature will be assumed to return 'id' and accept '.......' as arguments

how i finding state and city name from array?

+1  A: 

For regular expression support in Objective-C check out RegexKitLite. It provides category methods on NSString that support various regex matching and substitution.

Suresh Kumar
A: 

Have a look at [componentsSeparatedByCharactersInSet:][1]. If you supply numbers as the set you will get an array of strings which you can recombine into a numberless string.

Benedict Cohen