我在 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' 并接受 '.......' 作为参数”。
如何从结果中获取州和城市名称?