【发布时间】:2013-07-02 22:29:23
【问题描述】:
我有需要包含引号的字符串变量。毫不奇怪,将 "" 放入 "a string like this" 将结束字符串,然后创建一个新字符串。
例如:
writer.WriteLine("{"); //first line is ok
writer.WriteLine(" "profiles": { ");
// the word "profiles" not treated as just another part of the string
// but I need to write this text, quotes and all:
// "profiles": {
如何在字符串中加引号?
【问题讨论】:
-
它们通常被称为“双引号”或“引号”。
-
@alexisdm 相关但不重复,因为这是文字字符串中面临的不同问题,您不能只是
@"do \"this\""(文字字符串中没有转义,因此您无法转义引号标记以防止它们结束字符串!) -
@alexisdm 该问题的解决方案(
@"use ""double"" quotation marks",在前两个答案中表示)不适用于非文字字符串。只阅读标题,可能会认为它们是重复的,但阅读问题本身应该可以澄清问题,并且每个问题的答案与另一个无关。