I making an HTTP request in Objective-C and I get the reply from that is
200,8,"7 Infinite Loop, Cupertino, CA 95014, USA"
I want to extract the part "Cupertino, CA" from it. I wrote the following code:
NSArray *myArray = [result5 componentsSeparate开发者_开发技巧dByString:@","];
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 a warning for the line:
NSString * state = [[myArray objectAtIndex:4]
stringByReplacingOccurrencesOfRegex:@"[^0-9]" withString:@""];
which says "no -stringByReplacingOccurrenceoOfRegexwithString method found" and "Message without a matching method signature will be assumed to return 'id' and accept '.......' as arguments".
How do I get the state and city name from the result?
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.
精彩评论