Skip to content

Instantly share code, notes, and snippets.

@mrgarita
Created October 25, 2017 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrgarita/a5ddb21b1559b7cd166e136e46825cc9 to your computer and use it in GitHub Desktop.
Save mrgarita/a5ddb21b1559b7cd166e136e46825cc9 to your computer and use it in GitHub Desktop.
C#:CSVファイルを読み込む
using System;
using System.IO;
using System.Text;
namespace CSVファイルを読み込む
{
class Program
{
static void Main(string[] args)
{
try
{
// ファイルを読み取り形式で開く
StreamReader file = new StreamReader("tango.txt", Encoding.UTF8);
string line = null;
while ((line = file.ReadLine()) != null) // 1行ずつ読み込む
{
string[] tango = line.Split(','); // カンマで区切って配列に格納
Console.WriteLine(tango[0] + " " + tango[1]);
}
file.Close();
}
catch (Exception e)
{
Console.WriteLine(e.Message); // エラーメッセージを表示
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment