Created
December 19, 2012 19:58
-
-
Save cofearabi/4339944 to your computer and use it in GitHub Desktop.
(C#) read a csv text file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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