Rev | Line | |
---|
[1781] | 1 | using System.IO;
|
---|
| 2 |
|
---|
| 3 | namespace 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.