12
Answers

Write Text file with delimiter

j c

j c

10y
1.7k
1

 

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)