Skip to content

Instantly share code, notes, and snippets.

@cofearabi
Created December 19, 2012 19:58
Show Gist options
  • Save cofearabi/4339944 to your computer and use it in GitHub Desktop.
Save cofearabi/4339944 to your computer and use it in GitHub Desktop.
(C#) read a csv text file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualBasic.FileIO;
namespace cs_read_csv
{
class Program
{
static void Main(string[] args)
{
TextFieldParser parser = new TextFieldParser(@"C:\mdb\zzz.txt", Encoding.GetEncoding("Shift_JIS"));
parser.TextFieldType = FieldType.Delimited;
parser.SetDelimiters(","); // 区切り文字はコンマ
while (!parser.EndOfData)
{
string[] row = parser.ReadFields(); // 1行読み込み
Console.WriteLine(row[0] + "," + row[1] + "," + row[2]);
}
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment