-
June 19th, 2009, 12:30 PM
#1
[RESOLVED] How to add more spaces between lines to a text file ?
Hi,
tw.WriteLine(tw.NewLine);
I have this line wich add a space between the text in the text file i created .
Each time i press the button a new line is added with spaces between it .
How do i set how much spaces to add between the lines ?
For example now its making two empty line between each text how do i set it so it will make one space or 6 spaces how do i do it ?
This is the full code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace FileWriteRead
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
TextWriter tw = new StreamWriter(@"d:\date.txt",true);
tw.WriteLine(DateTime.Now);
tw.WriteLine(tw.NewLine);
tw.Close();
}
}
}
-
June 19th, 2009, 12:32 PM
#2
Re: How to add more spaces between lines to a text file ?
You use a loop when adding the new lines.
-
June 21st, 2009, 04:12 AM
#3
Re: How to add more spaces between lines to a text file ?
Originally Posted by Chocolade
Hi,
tw.WriteLine(tw.NewLine);
I have this line wich add a space between the text in the text file i created .
Each time i press the button a new line is added with spaces between it .
How do i set how much spaces to add between the lines ?
For example now its making two empty line between each text how do i set it so it will make one space or 6 spaces how do i do it ?
I do wish you wouldnt refer to a new line as a "space". A Space is what you get when you press the Space Bar -> " ", not the Return/Enter key
As Ed says, call WriteLine() [with no arguments!] in a loop:
Code:
//write 10 newlines
for int i=0;i<10;i++)
tw.WriteLine();
//or you can perform this hack:
tw.WriteLine( string.Join(Environment.NewLine, new string[10]) );
Yep, joining an array of 10 items using newline will result in a sequence of 9 new lines (one between each of the 10 empty elements). We call WriteLine to add the 10th.. thus 10 new lines are written to the file
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|