帮助bw.write,写两行以上++ [英] Help in bw.write , writing over 2 lines ++

查看:126
本文介绍了帮助bw.write,写两行以上++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我想创建一个按钮来保存.txt文件,并写出我在源代码中写的内容

hello

I want to create a button to save the .txt and , write what i''ve wrote in the source code

SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "Queries|*.txt";
            sfd.FileName = "blabla";
            sfd.Title = "Save Querie as";
            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string path = sfd.FileName;
                BinaryWriter bw = new BinaryWriter(File.Create(path));
                bw.Write(" ");
                bw.Dispose();
            }


但是,bw.Write(");应该是1行


but , bw.Write(" "); should be for 1 line

bw.Write("hi helo code project blabla etc");


但是,如果我要多行怎么办


but , what If I want many lines

bw.Write("Hello
code project
blabla
etc");


但是在那种情况下,它给了我错误.因为它显示我忘记添加);并且,开始了新的损坏行


but in that case , it gives me error. because it reads that I''ve forgot to add "); and , started new corrupted line
Is there any thing should make it?

推荐答案

是的-在需要换行的地方添加"\ n":
Yes - add a "\n" wherever you want a new line:
bw.Write("hi\nhelo\ncode project\nblabla\netc");

将产生:

hi
helo
code project 
blabla
etc


有一个简单的方法来实现.
您可以在字符串前面添加&"号,以表示它是包含回车符的文字.
There is a simple way to do this.
You can add the ampersand in front of your string which indicates that it is a literal including carriage returns.
bw.Write(@"Hello
code project
blabla
etc");


这篇关于帮助bw.write,写两行以上++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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