0

我在 Objective-C 中发出 HTTP 请求,我得到的答复是

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

我想从中提取“Cupertino, CA”部分。我写了以下代码:

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);

但是我收到了一条警告:

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

上面写着“没有找到 -stringByReplacingOccurrenceoOfRegexwithString 方法”和“没有匹配方法签名的消息将被假定返回 'id' 并接受 '.......' 作为参数”。

如何从结果中获取州和城市名称?

4

1 回答 1

0

看看[componentsSeparatedByCharactersInSet:][1]。如果您提供数字作为集合,您将获得一个字符串数组,您可以将其重新组合成一个无数字的字符串。

于 2010-02-17T10:13:57.100 回答