j c

j c

  • NA
  • 45
  • 0

Write Text file with delimiter

Feb 14 2014 6:13 PM

 

I am using below code to write a text file with  | delimiter

 

int i = 0;

            StreamWriter sw = null;

            sw = new StreamWriter(filePath, false);

            for (i = 0; i < dt.Columns.Count; i++)

            { sw.Write(dt.Columns[i].ToString() + "\t"); }

            sw.WriteLine();

            foreach (DataRow row in dt.Rows)

            { object[] array = row.ItemArray; for (i = 0; i < array.Length; i++)

            { sw.Write(array[i].ToString() + "\t"); }

              sw.WriteLine(); }

            sw.Close();

 

but it writes the text file  with | delimiter at the end of column and row ..

How can I not write the | delimiter at the end of Colum and row

 

Current result

Colum1 | column2| column3|

1001 |      1002 |       1003 |

  

And I would like to create file without the delimiter at the end of column and row

 

Colum1 | column2| column3

1001 |      1002 |       1003

 


Answers (12)