I'm looping through the rows and columns of a DataSet to write to a text file with a pipe delimiter. I have it working except I need to leave off the pipe from the last column. Is there a way for me to adjust the loop to loop through fields.count-1 and then refer to the last field outside of the loop?
foreach (object item in row.ItemArray)
{
d = d+ item.ToString() + "|";
}
You can join the contents of any IEnumerable (including arrays) using String.Join, eg:
var newText = String.Join("|",row.ItemArray);
You can use TrimEnd(Char[]) method like
d.TrimEnd(new char[]{'|'});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With