如何用双引号写入文本文件? [英] How to Write to a Text file with Double quotes?

查看:102
本文介绍了如何用双引号写入文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以告诉我如何使用双引号写入文本文件吗?



实际上我想要使用以下格式的文本文件



<< MAWB>>,160-3636 4834,2012/06/12,CX500,2012/06/08 ,170



但是用()标记写起来有点难:

< br $>


我得到的是:

<< MAWB>>,160-3636 4834,2012 / 06/12,CX500,2012 / 06 / 08,17,0



不是我所期待的。有人可以告诉我一个用()标记写文本文件的方法,这对我来说是一个很大的帮助。谢谢提前!!!我的意思是如何用双引号来坚持字符串



<< MAWB>>,160-3636 4834,2012 / 06/12,CX500,2012 / 06 / 08,17,0 TO< br /> 
< br />
<< MAWB>>,160-3636 4834,2012/06/12,CX500,2012/06 / 08,17,0

解决方案

写双引号我把\ in string.Example:



 textBox1.Text =  他伤心:\当生活给你柠檬时,你会做一个柠檬派对; 


< blockquote>像这样:



  string  textToWrite =  << MAWB>>,\160-3636 4834 \,2012/06/12,\ CX500\,2012/06 / 03,17,0\" ; 

File.WriteAllText( @ C:\Temp \ temp.txt,textToWrite);





查看MSDN 文档 [ ^ ]了解详情。


尝试在代码中包含escape charater [即反斜杠]在哪里尝试添加双引号。



例如:\您的数据\





寻找以下指示:

http:// forums .asp.net / t / 1053221.aspx / 1 [ ^ ]



http: //forums.codeguru.com/showthread.php?t=368839 [ ^ ]


Hi can some one tell me how to Write to a Text file with Double quotes?

Actually i want to text-file with the Following format

<<MAWB>>,"160-3636 4834",2012/06/12,"CX500",2012/06/08,17,0

But it is bit of hard to write with (") mark:


what i get is :
<<MAWB>>,160-3636 4834,2012/06/12,CX500,2012/06/08,17,0

Not what i expected.hence can some one could tell me a method for write the text file with a (")mark ,that would be a great help for me.Thanks in Advance!!!i mean how to perse the String with double quotes

<<MAWB>>,160-3636 4834,2012/06/12,CX500,2012/06/08,17,0  TO <br />
<br />
<<MAWB>>,"160-3636 4834",2012/06/12,"CX500",2012/06/08,17,0

解决方案

To write Double quotes I put \" in string.Example:

textBox1.Text = "He sad:\"When life gives you lemon, you make a lemon party\"";


Like this:

string textToWrite = "<<MAWB>>,\"160-3636 4834\",2012/06/12,\"CX500\",2012/06/03,17,0";

File.WriteAllText(@"C:\Temp\temp.txt", textToWrite);



Look at MSDN documentation [^]for details.


Try to include escape charater [i.e.,back slash] in the code where you are trying to add double quotes.

For ex: "\" YOUR DATA \""



Look for below pointers:
http://forums.asp.net/t/1053221.aspx/1[^]

http://forums.codeguru.com/showthread.php?t=368839[^]


这篇关于如何用双引号写入文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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