Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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:
C#
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:
C#
<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
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [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
Posted
Comments
BillWoodruff 25-Sep-20 8:22am    
What is not working ? What error messages ? Looks like you are mixing a WinForm app with a Console App. You definitely do not understand Process.Start.

You need to stop making code that will never compile, and go study the basics of C#.
dejf111 25-Sep-20 8:28am    
yes I'm just learning that's why I wrote here.
All that happens is a new text file opens and the one I'm drawing from and loads into the VS
dejf111 25-Sep-20 9:27am    
I study on web dotnetperls.com and what web page do you recomended? Thank you for advise
Sandeep Mewara 25-Sep-20 8:25am    
And what is the query here? Whats the problem you are stuck with?
dejf111 25-Sep-20 8:30am    
I'm self-taught so I don't know whether I combine it well
and I still don't speak English very well as you could notice :D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900