Collection to CSV - Set delimiter

MoDCore

New Member
Hi All!

I have been reading a couple of threads about saving a collection to CSV and they all seem to want to use comma as the delimiter.

In the Utility - Strings there is already input/output and code for this, but using a comma, how would one go about changing the delimiter to say | or && (or any other delimter we may need).

Thanks In advance
MoD
 

MoDCore

New Member
Have seen a solution for this using C# but cant seem to figure out yet how to add this code in without a Code" object having loads of errors.

Inputs:
Collection - Collection
Delimiter - Text
Target - Text

StringBuilder sb = new StringBuilder();
string[] columnNames = Collection.Columns.Cast<DataColumn>().
Select(column => column.ColumnName).
ToArray();
sb.AppendLine(string.Join(Delimiter, columnNames));
foreach (DataRow row in Collection.Rows)
{
string[] fields = row.ItemArray.Select(field => field.ToString()).
ToArray();
sb.AppendLine(string.Join(Delimiter, fields));
}
File.WriteAllText(Target, sb.ToString());​
 
Top