Как выбрать определенный столбец в текстовом файле и выполнить поиск строки? Если строка найдена, то извлеките всю строку целиком.
I want to search for a string in a specific column say column number 213 from a text file. And if the string is found then i want to display the whole row belonging to it.
Что я уже пробовал:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using Excel = Microsoft.Office.Interop.Excel; using System.Windows.Forms; namespace Loan { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { OpenFileDialog fdlg = new OpenFileDialog(); fdlg.Title = "C# Corner Open File Dialog"; fdlg.InitialDirectory = @"d:\test"; fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"; fdlg.FilterIndex = 2; fdlg.RestoreDirectory = true; if (fdlg.ShowDialog() == DialogResult.OK) { MessageBox.Show("selected file is :" + fdlg.FileName); } float counter = 0; string line; // Read the file and display it line by line. System.IO.StreamReader file = new System.IO.StreamReader(fdlg.FileName); try { while ((line = file.ReadLine()) != null) { //string[] col = line.Split(new string[] { " " }, StringSplitOptions.None); string[] col = line.Split(new string[] { " " }, StringSplitOptions.None); if (col.Contains("3")) { MessageBox.Show(counter.ToString() + ": " + line); counter++; } } } catch (IndexOutOfRangeException ae) { string err = ae.Message; } file.Close(); } } }