Delete last line in txt file
Posted
by
user3658127
on Stack Overflow
See other posts from Stack Overflow
or by user3658127
Published on 2014-06-11T09:11:48Z
Indexed on
2014/06/11
9:24 UTC
Read the original article
Hit count: 267
c#
|datagridview
I wrote a foreach loop for my datagridview to write all rows to txt file. I have a problem as it adds 2 empty lines at the end, as 1 row is full of empty cells after adding/reading to datagrid view. Is there any way to omit the last line or delete it in txt?
foreach (DataGridViewRow item in this.DB.Rows)
{
foreach (DataGridViewCell item2 in item.Cells)
{
if(item2.Value != null)
filewrite.Write(item2.Value.ToString() + " ");
}
filewrite.WriteLine("");
}
© Stack Overflow or respective owner