Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 替换目标c中的转义字符序列_Objective C_String - Fatal编程技术网

Objective c 替换目标c中的转义字符序列

Objective c 替换目标c中的转义字符序列,objective-c,string,Objective C,String,我有一个返回字符串和转义字符序列的查询。(例如“美国”) 我以这种方式使用stringByReplacingOccurrencesOfString: [theCountry stringByReplacingOccurrencesOfString:@"\"" withString:@""]; 但它仍然会留下一组引号。如果我再次尝试该方法以删除它们: [theCountry stringByReplacingOccurrencesOfString:@""" withString:@""]; 我

我有一个返回字符串和转义字符序列的查询。(例如“美国”)

我以这种方式使用
stringByReplacingOccurrencesOfString

[theCountry stringByReplacingOccurrencesOfString:@"\"" withString:@""];
但它仍然会留下一组引号。如果我再次尝试该方法以删除它们:

[theCountry stringByReplacingOccurrencesOfString:@""" withString:@""];
我会有一个不完整的报价集。。。 我需要去掉斜杠和双引号


有什么想法吗?

您需要避开反斜杠:

NSString* foo = @"USA\\\"";
NSLog(@"String [%@]", foo);
foo = [foo stringByReplacingOccurrencesOfString:@"\\\"" withString:@""];
NSLog(@"String [%@]", foo);
导致

2009-11-02 09:15:24.403 test[6098:903] String [USA\"]
2009-11-02 09:15:24.406 test[6098:903] String [USA]

事实上,你能澄清一下:你的字符串是否包含前导和尾随引号,你想从“USA”中得到USA\?