如何轻松地显示在字符串中的双引号在C#中? [英] How to easily display double quotes in strings in C#?

查看:1279
本文介绍了如何轻松地显示在字符串中的双引号在C#中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你有一个无数双引号的字符串,



在PHP中,你可以这样做:

  file.WriteLine('<控制:FormField名称=大街LabelText的=大街>'); 

在C#中,你必须这样做:

  file.WriteLine(<控制:FormField名称= \Strasse\LabelText的= \Strasse\>中); 



有没有在C#中的方法做,你可以在PHP做什么上面,有点像@ C:?\temp,它可以这样做,你不需要双斜杠



感谢弗雷德里克,这使得即使行情和在相当可读的String.Format大括号:

  file.WriteLine(的String.Format(@<文本框的文本= {{{绑定0}}}
风格={{DynamicResource FormularFieldTextBox}}/>中,字段名));


解决方案

有两种方式来表示在C#中的字符串报价:

  file.WriteLine(<控制:FormField名称= \Strasse\LabelText的= \Strasse\\ \\>中); 
file.WriteLine(@<控制:FormField名称=大街,LabelText的=大街,>中);


If you have a string with a numerous double quotes,

in PHP you can do this:

file.WriteLine('<controls:FormField Name="Strasse" LabelText="Strasse">');

in C# you have to do this:

file.WriteLine("<controls:FormField Name=\"Strasse\" LabelText=\"Strasse\">");

Is there a way in C# to do what you can do above in PHP, something like the @"c:\temp" which you can do so that you don't need double slashes?

Thanks Fredrik, that makes even quotes and curly brackets in a String.Format fairly readable:

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

解决方案

There are two ways to represent quotes in C# strings:

file.WriteLine("<controls:FormField Name=\"Strasse\" LabelText=\"Strasse\">");
file.WriteLine(@"<controls:FormField Name=""Strasse"" LabelText=""Strasse"">");

这篇关于如何轻松地显示在字符串中的双引号在C#中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆