【问题标题】:How do I include a " " inside a string in objective c [duplicate]如何在目标 c 的字符串中包含“” [重复]
【发布时间】:2023-03-05 10:07:01
【问题描述】:

可能重复:
How to escape double quotes in string?

如何在字符串中包含 "" 并阻止它结束字符串?我有一个 html 字符串,但无法定义元素,因为我不能使用“”,请问有什么帮助吗?

【问题讨论】:

标签: objective-c string comma


【解决方案1】:

用反斜杠转义引号,如下所示:

@"A string with \"quotes\" around the word \"quotes\"."

如果你用NSLog()打印它,它会输出为:

A string with "quotes" around the word "quotes".

Objective-C 继承了它从 C 中转义的字符串文字,还有一些 C 字符串转义码 are listed here 等等。

【讨论】:

    【解决方案2】:

    所以你想要一个字符串中的引号? 我想你想要这样的东西:

    "string with quote: \" << the quote"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-12
      • 2016-10-22
      • 1970-01-01
      • 1970-01-01
      • 2016-08-07
      • 2016-04-01
      • 1970-01-01
      相关资源
      最近更新 更多