テキストファイルがあります。私のプログラムでは次のようにします:テキストファイルを読み込んで行単位で処理する
1 - 行数とファイルパスを表示します。
各行に2ループ。
var lines = File.ReadLines(@"C:\\test.txt");
編集(回答)
public static string[] local_file; // make a string array to load the file into it
int i = 0; // index of lines
try
{
OpenFileDialog op = new OpenFileDialog // use OpenFileDialog to choose your file
{
Filter = "Combos file (*.txt)|*.txt" ;// select only text files
}
if (op.ShowDialog() == DialogResult.OK)
{
local_file= File.ReadAllLines(op.FileName);// load all the contents of the file into the array
string count = "lines = " + Convert.ToString(local_file.Length); // number of lines
string file_name = op.FileName; // show the file name including the path
}
for (i; i < local_file.Length; i++)// loop through each line
{
// do something here remember to use local_file[i] for the lines
}
}catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
ある場合 後で、それぞれの行を分割するためのユーザforeachのは、あなたが「アリ」の実際の行(あなたのループがあるを確認し、コードの一部を表示してくださいすることができます?FirstFirstOrDefault?) – nabuchodonossor
すべての行が表示されますが、最初の行( 'FirstOrDefault')だけが表示されます。なぜそれが最初の行以上に読み込まれるのでしょうか?これは非常に基本的な質問のようなもので、特定の問題ではなく言語の知識が一般的でないことを示唆しています... – Chris
教授Googleは "c-sharpについてテキストファイルからテキストを読む方法"について教えてくれるでしょう –