Created
March 17, 2017 01:07
Star
You must be signed in to star a gist
TextFieldParserの使用例
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
string filePath = Console.ReadLine(); | |
string fileName = filePath.Substring(filePath.LastIndexOf('\\') + 1).Replace('"',' '); | |
// ファイル名と文字エンコードを指定してパーサを実体化 | |
using (TextFieldParser txtParser = | |
new TextFieldParser( | |
fileName, | |
Encoding.GetEncoding("shift_jis"))) | |
{ | |
// 内容は区切り文字形式 | |
txtParser.TextFieldType = FieldType.Delimited; | |
// デリミタはカンマ | |
txtParser.SetDelimiters(","); | |
// ファイルの終わりまで一行ずつ処理 | |
while (!txtParser.EndOfData) | |
{ | |
// 一行を読み込んで配列に結果を受け取る | |
splittedResult = txtParser.ReadFields(); | |
using (StreamWriter writer = | |
new StreamWriter("sql.txt", true, Encoding.GetEncoding("shift_jis"))) | |
{ | |
// ここでテキストに書き出し | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment