Hello everybody I try one exercise
1) Create a form with one button and a text line (button + textbox)
2) You will then enter the location of the text file in the text line
3) After clicking on the button, the program should load the text and at the same time create a second empty text (it doesn't matter where)
4) Then he had to go through the individual lines and the moment he finds a line with 3 stars, he looks at the previous line, reads the number of the map sheet from it (here 0404-D-07) and writes it in the new textbook.
5) After passing all lines, close both texts
6) The result should therefore be a text with the following lines:
0404-D-07
0404-D-10
I've placed it before but I think I've moved on since then but it's still not the right
What I have tried:
my code to this time:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ukol
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Process.Start("C:\\Users\\mrazekd\\Downloads\\PrubehPripravyPat.txt");
FileStream fs = null;
string nFile = @"C:\Users\mrazekd\Documents\newText.txt";
fs = new FileStream(nFile, FileMode.OpenOrCreate, FileAccess.ReadWrite);
Process.Start(@"C:\Users\mrazekd\Documents\newText.txt");
}
}
}
and program:
<pre>using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ukol
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
{
string[] value1 = File.ReadAllLines("C:\\Users\\mrazekd\\Downloads\\PrubehPripravyPat.txt");
for (var i = 0; i < value1.Length; i++)
{
var thisLine = value1[i];
if (i > 0 && thisLine.StartsWith("***") && thisLine.EndsWith("useky"))
{
Console.WriteLine(value1[i - 1]);
}
int startIndex = 16;
int length = 9;
String value = thisLine.Substring(startIndex, length);
string value2 = string.Copy(value);
using (StreamWriter writer = new StreamWriter(@"C:\Users\mrazekd\Documents\newText.txt"))
{
writer.WriteLine(value2);
}
Process open = new Process();
open.StartInfo.FileName = @"C:\Users\mrazekd\Documents\newText.txt";
open.Close();
}
}
}
}
}
but I don't know what to do about it
every advice will be gold
thank you very much