Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/3.2/DataExport/CSVWriter.cs @ 1875

Last change on this file since 1875 was 1781, checked in by mstoeger, 16 years ago

Data Export (CSV) #588

File size: 1.0 KB
RevLine 
[1781]1using System.IO;
2
3namespace HeuristicLab.Visualization.DataExport {
4  public class CSVWriter {
5    private readonly StreamWriter sw;
6
7    private string seperator = ";";
8    private string stringQuotes = "\"";
9
10    private bool firstInLine = true;
11
12    public CSVWriter(StreamWriter sw) {
13      this.sw = sw;
14    }
15
16    public void AddString(string text) {
17      Add(stringQuotes + text + stringQuotes);
18    }
19
20    public void AddNumber(double value) {
21      Add(value.ToString());
22    }
23
24    public void AddEmpty() {
25      Add("");
26    }
27
28    private void Add(string text) {
29      if (!firstInLine)
30        sw.Write(seperator);
31
32      sw.Write(text);
33
34      firstInLine = false;
35    }
36
37    public void NewLine() {
38      sw.WriteLine();
39      firstInLine = true;
40    }
41
42    public string Seperator {
43      get { return seperator; }
44      set { seperator = value; }
45    }
46
47    public string StringQuotes {
48      get { return stringQuotes; }
49      set { stringQuotes = value; }
50    }
51  }
52}
Note: See TracBrowser for help on using the repository browser.