Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8973557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:28:28+00:00 2026-06-15T18:28:28+00:00

Firstly, i’d just like to mention that I’ve only started learning C# a few

  • 0

Firstly, i’d just like to mention that I’ve only started learning C# a few days ago so my knowledge of it is limited.

I’m trying to create a program that will parse text files for certain phrases input by the user and then output them into a new text document.

At the moment, i have it the program searching the original input file and gathering the selected text input by the user, coping those lines out, creating new text files and then merging them together and also deleting them afterwards.

I’m guessing that this is not the most efficient way of creating this but i just created it and had it work in a logical manor for me to understand as a novice.

The code is as follows;

private void TextInput1()
    {
        using (StreamReader fileOpen = new StreamReader(txtInput.Text))
        {
            using (StreamWriter fileWrite = new StreamWriter(@"*DIRECTORY*\FIRSTFILE.txt"))
            {
                string file;
                while ((file = fileOpen.ReadLine()) != null)
                {
                    if (file.Contains(txtFind.Text))
                    {
                            fileWrite.Write(file + "\r\n");
                    }
                }
            }
        }
    }

    private void TextInput2()
    {
        using (StreamReader fileOpen = new StreamReader(txtInput.Text))
        {
            using (StreamWriter fileWrite = new StreamWriter(@"*DIRECTORY*\SECONDFILE.txt"))
            {
                string file;
                while ((file = fileOpen.ReadLine()) != null)
                {
                    if (file.Contains(txtFind2.Text))
                    {
                        fileWrite.Write("\r\n" + file);
                    }
                }
            }
        }
    }

    private static void Combination()
    {
        ArrayList fileArray = new ArrayList();

        using (StreamWriter writer = File.CreateText(@"*DIRECTORY*\FINALOUTPUT.txt"))
        {

            using (StreamReader reader = File.OpenText(@"*DIRECTORY*\FIRSTFILE.txt"))
            {
                writer.Write(reader.ReadToEnd());
            }

            using (StreamReader reader = File.OpenText(@"*DIRECTORY*\SECONDFILE.txt"))
            {
                writer.Write(reader.ReadToEnd());
            }
        }

    }

    private static void Delete()
    {
        if (File.Exists(@"*DIRECTORY*\FIRSTFILE.txt"))
            {
                File.Delete(@"*DIRECTORY*\FIRSTFILE.txt");
            }

        if (File.Exists(@"*DIRECTORY*\SECONDFILE.txt"))
            {
                 File.Delete(@"*DIRECTORY*\SECONDFILE.txt");
            }

    }

The output file that is being created is simply outputting the first text input followed by the second. I am wondering if it is possible to be able to merge them into 1 file, 1 line at a time as it is a consecutive file meaning have the information from Input 1 followed 2 is needed rather than all of 1 then all of 2.

Thanks, Neil.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:28:29+00:00Added an answer on June 15, 2026 at 6:28 pm

    To combine the two files content in an one merged file line by line you could substitute your Combination() code with this

    string[] file1 = File.ReadAllLines("*DIRECTORY*\FIRSTFILE.txt");
    string[] file2 = File.ReadAllLines("*DIRECTORY*\SECONDFILE.txt");
    
    using (StreamWriter writer = File.CreateText(@"*DIRECTORY*\FINALOUTPUT.txt"))
    {
        int lineNum = 0;
        while(lineNum < file1.Length || lineNum < file2.Length)
        {
            if(lineNum < file1.Length)
                writer.WriteLine(file1[lineNum]);
            if(lineNum < file2.Length)
                writer.WriteLine(file2[lineNum]);
            lineNum++;
        }
    }
    

    This assumes that the two files don’t contains the same number of lines.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly, this is going to sound like homework, but it ain't. Just a problem
Firstly, I would like to say that I don't mean the full path, what
Firstly, let me just say that I'm very new to JSR-170 and Jackrabbit/Lucene in
Firstly I have to say that I have been like 2 weeks researching on
Firstly I have a class signature that looks like this: internal class JobStore :
Firstly, this seems like something that should have been asked before, but I cannot
Firstly to show you what I am trying to achieve in the view, a
Firstly, I wrote my customized setter for an NSString* like this: - (void)setDateString:(NSString *)newDateString
Firstly some background,.. IVe started a new job as PHP developer with a company
Firstly I would say that I have read this post however I still have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.