C# CSVファイルのデーター取得

FileをStreamReaderで読み込み、データーを取得する

// Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); // 必要なら

string csvFileName1 = @"D:\data.csv";
var enc = System.Text.Encoding.GetEncoding("Shift_JIS");
StreamReader sr = new StreamReader(csvFileName1, enc);
 
while (!sr.EndOfStream)
{
    string line = sr.ReadLine() ?? "";
    string[] values = line.Split(',');
 
    Debug.WriteLine("*****************************");
 
    foreach (string value in values)
    {
 
        // .Trim(new char[] { '"' }) ダブルクォーテーション削除
        Debug.WriteLine(value.Trim(new char[] { '"' }));
    }
}

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください