我有一个要修改的 .csv 文件。这是文件的格式:
Id, UTMGridEast, UTMGridNorth, LocDate, LocTime, Species
我已经做的是创建一个包含所有这些值的数组列表,但我想做的是创建一个包含所有值的数组列表,并且数据集中的每一行都是另一个数组。这是因为我需要编辑这些字段UTMGridEast
,UTMGridNorth
然后将它们重新插入到数组列表中。
我的 GUI 只包含两个按钮,到目前为止,这是我的代码:
public partial class MainWindow : Window
{
private string _filename;
private string[] _splitValues;
public MainWindow()
{
InitializeComponent();
}
private void btnLoad_Click(object sender, RoutedEventArgs e)
{
// Configure open file dialog box
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.FileName = "Dataset"; // Default file name
dlg.DefaultExt = ".txt"; // Default file extension
dlg.Filter = "Commar Seperated Values (.csv)|*.csv" ; // Filter files by extension
// Show open file dialog box
Nullable<bool> result = dlg.ShowDialog();
// Process open file dialog box results
if (result == true)
{
// Open document
_filename = dlg.FileName;
txtFilePath.Text = _filename;
}
}
private void btnConvert_Click(object sender, RoutedEventArgs e)
{
ConvertToLatLong();
}
private void ConvertToLatLong()
{
string textFile = System.IO.File.ReadAllText(_filename);
foreach (var value in textFile)
{
_splitValues = textFile.Split(',');
Console.WriteLine("Split values: " + _splitValues[value]);
}
}
}