objective-c 如何在字符串中转义双引号?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1352323/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to escape double quotes in string?
提问by 4thSpace
I'd like double quotes to appear within the following string so it looks like:
我希望双引号出现在以下字符串中,因此它看起来像:
"hi there == "
Here's the code I'm using:
这是我正在使用的代码:
NSMutableString *s = [[NSMutableString alloc] init];
[s appendString:@""""];
[s appendString:@"hi there == ""\n\r"];
Instead I only get:
相反,我只得到:
hi there ==
Any ideas?
有任何想法吗?
回答by user151019
[s appendString:@"hi there == \"\n\r"];
\"is what is needed for "- This is standard C formatting.
\"是需要的"- 这是标准的 C 格式。
回答by Amit Ajmera
Although Its late but we can Try this:
虽然它晚了但我们可以试试这个:
[NSString stringWithFormat:@"\"Hi There=\" Other text"];
回答by user2181174
You have to append a slash (\) before the quote (") to ge the expected output.
您必须在引号 (") 之前附加一个斜杠 (\) 才能获得预期的输出。
[s appendString:@"\"hi there == \"\n\r"];
Output will be "hi there == "
输出将是“你好==”

