From 6ce4fdfb0eec5d2668780d2472e9f2fb9ba0e338 Mon Sep 17 00:00:00 2001 From: malcpps Date: Mon, 13 Mar 2017 10:34:55 +0000 Subject: [PATCH] Avoid ambiguous exported data. Fix issue #3 by checking if comma is the decimal separator, and if so, use semi-colon instead to separate exported data. I've tested that this doesn't change existing behaviour in the UK (which uses '.' as the decimal separator). I've not tested yet in a locale where comma is the decimal separator. --- SingleTact Demo/GUI.cs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/SingleTact Demo/GUI.cs b/SingleTact Demo/GUI.cs index 80a5283..4a331ea 100644 --- a/SingleTact Demo/GUI.cs +++ b/SingleTact Demo/GUI.cs @@ -211,6 +211,22 @@ public void AddData(double time, double[] measurements) graph_.AxisChange(); } + /// + /// Finds a character to separate exported values. + /// + /// A semi-colon for locales where comma is the decimal + /// separator; otherwise a comma. + private string safeSeparator() + { + double testValue = 3.14; + string testText = testValue.ToString(); + + if (testText.IndexOf(',') < 0) + return ","; + + return ";"; + } + //Save data to CSV private void buttonSave_Click(object sender, EventArgs e) { @@ -229,16 +245,19 @@ private void buttonSave_Click(object sender, EventArgs e) if (saveDataDialog.ShowDialog() == DialogResult.OK) { + // To fix Issue 3, separate exported values by semi-colon instead + // of comma if current locale's decimal separator is comma. + string separator = safeSeparator(); string saveFileName = saveDataDialog.FileName; StreamWriter dataWriter = new StreamWriter(saveFileName, false, Encoding.Default); //Write a header - dataWriter.WriteLine("Time (s)" + "," + "Value (0 = 0 PSI 511 = Full Scale Range)"); + dataWriter.WriteLine("Time (s)" + separator + "Value (0 = 0 PSI 511 = Full Scale Range)"); //Just export first trace (we only support 1 sensor) for (int i = 0; i < dataBuffer_.data[0].Count; i++) { - dataWriter.WriteLine(dataBuffer_.data[0][i].X + "," + dataBuffer_.data[0][i].Y); + dataWriter.WriteLine(dataBuffer_.data[0][i].X + separator + dataBuffer_.data[0][i].Y); } dataWriter.Close();