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

  • SEARCH
  • Home
  • 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 836321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:57:46+00:00 2026-05-15T04:57:46+00:00

I’m writing a program for some data entry I have to periodically do. I

  • 0

I’m writing a program for some data entry I have to periodically do. I have begun testing a few things that the program will have to do but i’m not sure about this part.

What i need this part to do is:

read a .txt file of data

take the first 12 characters from each line

take the first 12 characters from each line of the data that has been entered in a multi-line text box

compare the two lists line by line

if one of the 12 character blocks from the multi-line text box match one of the blocks in the .txt file then overwrite that entire line (only 17 characters in total)

if one of the 12 character blocks from the multi-line text box DO NOT match any of the blocks in the.txt file then append that entire line to the file

thats all it has to do.

i’ll do an example:

TXT FILE:

G01:78:08:32 JG05
G08:80:93:10 JG02
G28:58:29:28 JG04

MULTI-LINE TEXT BOX:

G01:78:08:32 JG06
G28:58:29:28 JG03
G32:10:18:14 JG01
G32:18:50:78 JG07

RESULTING TXT FILE:

G01:78:08:32 JG06
G08:80:93:10 JG02
G28:58:29:28 JG03
G32:10:18:14 JG01
G32:18:50:78 JG07

as you can see lines 1 and 3 were overwriten, line 2 was left alone as it did not match any blocks in the text box, lines 4 and 5 were appended to the file.

thats all i want it to do.

How do i go about this?

Thanks in advance

Edit

The code i’m using is this:

        private void WriteToFile()
    {
         // Read all lines from file into memory
        System.IO.StreamReader objReader = new System.IO.StreamReader("Jumpgate List.JG");
        List<String> fileTextList = new List<String>();
                 do
                     {
                         fileTextList.Add(objReader.ReadLine());
                     }
                 while (objReader.Peek() != -1);

                 objReader.Close();

         // Read all lines from the Input textbox into memory
             System.IO.StringReader objReaderi = new System.IO.StringReader(txtInput.Text);
             List<String> inputTextList = new List<String>();
                 do
                     {
                         inputTextList.Add(objReaderi.ReadLine());
                     } 
                 while (objReaderi.Peek() != -1);

                 objReaderi.Close();

         for(int i=0;i<fileTextList.Count;i++)
             {
                 for(int j=0;j<inputTextList.Count;j++)
                  //compare the first 12 characters of each string
                  if (String.Compare(fileTextList[i], 0, inputTextList[j], 0, 12) == 0) // strings are equal
                     {
                       //replace the fileTextList string with the inputTextList string
                         fileTextList[i] = inputTextList[j];
                       // now that you have matched you inputTextList line you remember not to append it at the end
                        inputTextList[j] = String.Empty; // or nothing
                     }
             }

          for(int i=0;i<inputTextList.Count;i++)
             {
                 if (!string.IsNullOrEmpty(inputTextList[i])) fileTextList.Add(inputTextList[i]);
              }

          System.IO.StreamWriter objWriter = new System.IO.StreamWriter("Jumpgate List.JG");

          // Overwrite the Jumpgate List.JG file using the updated fileTextList
          objWriter.Write(fileTextList);

          objWriter.Close();

}

However, when i open the txt file all i get is: System.Collections.Generic.List`1[System.String]

  • 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-05-15T04:57:46+00:00Added an answer on May 15, 2026 at 4:57 am

    I’m not going to write the whole code for doing this but it would be something like this:

    Disclaimer: I have not used a code editor to try the code, just wrote it here, hopefully you’ll get the idea and fill in the missing pieces 🙂

    1) get all the lines in the file in a list. Something like this

            StreamReader rd = new StreamReader("sadasd");
            List<String> llist = new List<String>();
                do
                {
                    llist.Add(rd.ReadLine());
    
                } while (rd.Peek() != -1);
    

    2) get all the lines in your multiline text box (the procedure should be similar to the one above): multiTextList

    3) now that you can compare the content of the 2 lists iterating through them

    for(int i=0;i<fileTextList.Count;i++)
    {
        for(int j=0;j<multiTextList.Count;j++)
         //compare the first 12 characters of each string
         if String.Compare(fileTextList[i], 0, multiTextList[j], 0, 12) == 0 // strings are equal
    {
          //replace the initial line with whatever you want
           fileTextList[i] = //whatever
          // now that you have matched you multiTextList line you remember not to append it at the end
           multiTextList[j] = String.empty // or nothing
    }
    }
    

    4) at the end you will have in fileTextList the initial rows, modified where necessary
    In multiTextList you will have only the lines that were not matched so we add them to the initial file rows

          for(int i=0;i<multiTextList.Count;i++)
            {
    if !string.isnullorempty(multitextlist[i]) fileTextList.add(multitextlist[i])
             }
    

    5) now in fileTextList you have all the rows you require so you can print them one by one in a file and you have your result

     StringBuilder lSb = new StringBuilder();
                for (int i = 0; i < fileTextList.Count; i++)
                {
                    lSb.AppendLine(fileTextList[i]);
                }
                File.WriteAllText(@"C:/test2.txt",lSb.ToString());
    

    In C:/test2.txt you should have the results.

    Hope this helps!

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

Sidebar

Ask A Question

Stats

  • Questions 422k
  • Answers 422k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If I got your question right you need to implement… May 15, 2026 at 11:26 am
  • Editorial Team
    Editorial Team added an answer There doesn't seem to be any particular support for Basic… May 15, 2026 at 11:26 am
  • Editorial Team
    Editorial Team added an answer A couple of ways: In your web.config on the customErrors… May 15, 2026 at 11:26 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.