如何从 Objective-C 中的 NSMutableString 获取逗号分隔值?
我在 Objective-C 中发出 HTTP 请求,得到的回复是
200,8,"7 Infinite Loop,库比蒂诺,CA 95014,美国"
我想从中提取“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”并接受“.......” ' 作为参数”。
如何从结果中获取州和城市名称?
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 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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看
[componentsSeparatedByCharactersInSet:][1]
。如果您提供数字作为集合,您将获得一个字符串数组,您可以将其重新组合成一个无数字的字符串。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.