Skip to content

Commit 6ce4fdf

Browse files
committed
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.
1 parent 3351529 commit 6ce4fdf

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

SingleTact Demo/GUI.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,22 @@ public void AddData(double time, double[] measurements)
211211
graph_.AxisChange();
212212
}
213213

214+
/// <summary>
215+
/// Finds a character to separate exported values.
216+
/// </summary>
217+
/// <returns>A semi-colon for locales where comma is the decimal
218+
/// separator; otherwise a comma.</returns>
219+
private string safeSeparator()
220+
{
221+
double testValue = 3.14;
222+
string testText = testValue.ToString();
223+
224+
if (testText.IndexOf(',') < 0)
225+
return ",";
226+
227+
return ";";
228+
}
229+
214230
//Save data to CSV
215231
private void buttonSave_Click(object sender, EventArgs e)
216232
{
@@ -229,16 +245,19 @@ private void buttonSave_Click(object sender, EventArgs e)
229245

230246
if (saveDataDialog.ShowDialog() == DialogResult.OK)
231247
{
248+
// To fix Issue 3, separate exported values by semi-colon instead
249+
// of comma if current locale's decimal separator is comma.
250+
string separator = safeSeparator();
232251
string saveFileName = saveDataDialog.FileName;
233252
StreamWriter dataWriter = new StreamWriter(saveFileName, false, Encoding.Default);
234253

235254
//Write a header
236-
dataWriter.WriteLine("Time (s)" + "," + "Value (0 = 0 PSI 511 = Full Scale Range)");
255+
dataWriter.WriteLine("Time (s)" + separator + "Value (0 = 0 PSI 511 = Full Scale Range)");
237256

238257
//Just export first trace (we only support 1 sensor)
239258
for (int i = 0; i < dataBuffer_.data[0].Count; i++)
240259
{
241-
dataWriter.WriteLine(dataBuffer_.data[0][i].X + "," + dataBuffer_.data[0][i].Y);
260+
dataWriter.WriteLine(dataBuffer_.data[0][i].X + separator + dataBuffer_.data[0][i].Y);
242261
}
243262

244263
dataWriter.Close();

0 commit comments

Comments
 (0)