Typical way of creating a CSV string (pseudocode):
Just a thought, but remember to handle comma's and quotation marks (") in the field values, otherwise your CSV file may break the consumers reader.