我怎样才能把引号中的字符串? [英] How can I put quotes in a string?

查看:125
本文介绍了我怎样才能把引号中的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要写一个字符串到一个文本文件,但是当我使用它引号字符C#编译器发现错误

I need to write a string literal to a text file, but the C# compiler finds errors when I use quote characters in it.

我当前的代码:

writeText.WriteLine("<?xml version="1.0" encoding="utf-8"?>");



我需要为文本文件的输出是:

I need the output for the text file to be:

<?xml version="1.0" encoding="utf-8"?>



我怎样才能把引号字符的字符串在C#?

How can I put quote characters in strings in C#?

推荐答案

您需要转义引号把它们放在一个字符串。有这样两种方式。在普通字符串中使用反斜杠:

You need to escape the quotation marks to put them in a string. There is two ways of doing this. Using backslashes in a regular string:

writeText.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");



在@ -delimited字符串中使用双引号quoation:

Using double quoation marks in a @-delimited string:

writeText.WriteLine(@"<?xml version=""1.0"" encoding=""utf-8""?>");

这篇关于我怎样才能把引号中的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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