using System; using System.IO; using System.Windows.Forms; namespace mise2 { public partial class Form1 : Form { private String filePath_input = string.Empty; public Form1() { InitializeComponent(); richTextBox1.AutoSize = true; } private void button1_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = @"C:\Users\"; openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; openFileDialog.FilterIndex = 2; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { filePath_input = openFileDialog.FileName; textBox1.Text = filePath_input; } } private string FindLineAboveAsterisks(string path) { TextReader sr = File.OpenText(path); return FindLineAboveAsterisks(sr); } private string FindLineAboveAsterisks(TextReader reader) { string result = reader.ReadLine(); string line = string.Empty; while (result is object && (line = reader.ReadLine()) is object) { int startIndex = 21; int length = 9; if (line.Contains("***")) { return result; } { result = line.Substring(startIndex, length); } } return string.Empty; } private void button2_Click(object sender, EventArgs e) { richTextBox1.Text = FindLineAboveAsterisks(filePath_input); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)