変更したい .csv ファイルがあります。ファイルの形式は次のとおりです。
Id, UTMGridEast, UTMGridNorth, LocDate, LocTime, Species
私がすでに行ったことは、これらすべての値の配列リストを作成することですが、私がやりたいのは、すべての値の配列リストを作成することであり、データセットの各行は別の配列です。これは、フィールドを編集してから、それらを arraylist に再挿入する必要があるためUTMGridEast
ですUTMGridNorth
。
私の GUI は 2 つのボタンだけで構成されています。これまでのコードは次のとおりです。
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]);
}
}
}