使用@符号时如何在字符串中使用双引号?

时间:2022-09-15 13:02:36

I need to use double quotes in a string that uses the @ symbol. Using double quotes is breaking the string. I tried escaping with \, but that doesn't work. Ideas?

我需要在使用@符号的字符串中使用双引号。使用双引号会破坏字符串。我尝试用\来逃避,但这不起作用。想法?

使用@符号时如何在字符串中使用双引号?

3 个解决方案

#1


14  

You double the quotes inside a verbatim string to get a quote character.

您将逐字字符串中的引号加倍以获取引号字符。

This makes your given sample:

这样就可以得到你的样品:

(@"PREFIX rdfs: <" + rdfs + @">
      SELECT ?s ?p ?o
        WHERE { ?s ?p rdfs:Literal }
              {?s rdfs:label ""date""}");

#2


21  

I believe this should work:

我相信这应该有效:

string myString = @"Here is my ""quoted"" text.";

#3


0  

You can use this if you want to write into a file :

如果要写入文件,可以使用此方法:

string myString = @"Here is my ""quoted""text.";
myString.Replace(@"""",@"&quot;");

#1


14  

You double the quotes inside a verbatim string to get a quote character.

您将逐字字符串中的引号加倍以获取引号字符。

This makes your given sample:

这样就可以得到你的样品:

(@"PREFIX rdfs: <" + rdfs + @">
      SELECT ?s ?p ?o
        WHERE { ?s ?p rdfs:Literal }
              {?s rdfs:label ""date""}");

#2


21  

I believe this should work:

我相信这应该有效:

string myString = @"Here is my ""quoted"" text.";

#3


0  

You can use this if you want to write into a file :

如果要写入文件,可以使用此方法:

string myString = @"Here is my ""quoted""text.";
myString.Replace(@"""",@"&quot;");