Vuk Stanojevic

Vuk Stanojevic

  • 1.6k
  • 140
  • 44.8k

c# add carriage return and line feed

Nov 3 2020 10:45 AM
Hi everyone,
i'm exporting datagridview to txt file.
first 2 lines of txt are defined in advanced.
other lines of txt should be exported from datagridview.
I manage to do it, but for each line which will be written in txt i need to add 0x0D carriage return and 0x0A line feed.
Can you help me how to add carriage and line feed.
My code is bellow.
Thank you.
  1. tw.WriteLine(cban + cname + ccity + date + blanko + mbank + nula).ToString();// on the end of this line i have to add carriage return(0x0D), and Line feed (0x0A)  
  2. tw.WriteLine(cban + cname + ccity + totamount.ToString() + totalxml.ToString() + blanko2 + type);// on the end of this line i have to add carriage return(0x0D), and Line feed (0x0A)  
  3. for (int i = 0; i <= dataGridView1.Rows.Count - 1; i++)  
  4. {  
  5. for (int j = 0; j <= dataGridView1.Columns.Count - 1; j++)  
  6. {  
  7. sLine = sLine + dataGridView1.Rows[i].Cells[j].Value;  
  8. }  
  9. tw.WriteLine(sLine); //also for each line written from datagridview i have to add on the end of each line carriage return(0x0D), and Line feed (0x0A)  
  10. sLine = "";  
  11. }  

Answers (7)