如何在C#中轻松显示字符串中的双引号?

Edw*_*uay 8 c# string

如果你有一个带有大量双引号的字符串,

在PHP中你可以这样做:

file.WriteLine('<controls:FormField Name="Strasse" LabelText="Strasse">');
Run Code Online (Sandbox Code Playgroud)

在C#中你必须这样做:

file.WriteLine("<controls:FormField Name=\"Strasse\" LabelText=\"Strasse\">");
Run Code Online (Sandbox Code Playgroud)

在C#中有没有办法在PHP上做你能做的事情,比如@"c:\ temp",你可以这样做,你不需要双斜线?

感谢Fredrik,它使String.Format中的引号和花括号相当可读:

    file.WriteLine(String.Format(@"<TextBox Text=""{{Binding {0}}}""
 Style=""{{DynamicResource FormularFieldTextBox}}""/>", fieldName));
Run Code Online (Sandbox Code Playgroud)

Fre*_*örk 27

在C#字符串中有两种表示引号的方法:

file.WriteLine("<controls:FormField Name=\"Strasse\" LabelText=\"Strasse\">");
file.WriteLine(@"<controls:FormField Name=""Strasse"" LabelText=""Strasse"">");
Run Code Online (Sandbox Code Playgroud)


Yur*_*ich 7

"<controls:FormField Name='Strasse' LabelText='Strasse'>".Replace("'", "\"")
Run Code Online (Sandbox Code Playgroud)

这不是很好,但关于唯一的选择.

或@""""insted of"你可以使用""