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 8002031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:15:01+00:00 2026-06-04T16:15:01+00:00

Im trying to write a simple program that will take 2 multi line inputs

  • 0

Im trying to write a simple program that will take 2 multi line inputs from 2 textboxes, put them in 2 arrays and compare them.

I want to check if an entry in array 1 (each line of textbox 1 is a separate entry in array 1) is in array 2 (each line of text box 2 is a separate entry in array 2).

then output the results to a textbox.

for example:

Array 1 “one, two, three, four, six”

Array 2 “one, three, five, four”

it should output:

one = found
two = not found
three = found
four = found
six = not found

The code i have so far is as follows:

 private void button1_Click(object sender, EventArgs e)
    {
         textBox3.Text = "";
         string[] New = textBox1.Text.Split('\n');
         string[] Existing = textBox2.Text.Split('\n');


       //for each line in textbox1's array
        foreach (string str in New)
        {

            //if the string is present in textbox2's array
            if (Existing.Contains(str))
            {
                textBox3.Text = "   ##" + textBox3.Text + str + "found";
            }
            /if the string is not present in textbox2's array
            else

            {
                textBox3.Text = "    ##" +textBox3.Text + str + "not found";
            }
        }


    }

This is not working correctly if there is more than one line in the either textbox – i cant figure out why.. the following is happening in test runs:

Array 1 - "One"
Array 2 - "One"
Result = One Found


Array 1 - "One"
Array 2 - "One, Two"
Result = One Not Found


Array 1 - "One, Two"
Array 2 - "One, Two"
Result = One found, Two Found

Array 1 - "One, Two, Three"
Array 2 - "One, Two"
Result - One Found, Two Not Found, Three Not Found

Thanks in advance

  • 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-04T16:15:03+00:00Added an answer on June 4, 2026 at 4:15 pm

    This is not working correctly if there is more than one line in the either textbox – can anyone figure out why?

    You should work on diagnosing problems yourself – I suspect that a simple breakpoint just before the loop, following by examining the arrays, would find the issue immediately.

    I’m pretty sure the problem is just that you should be splitting on "\r\n" instead of '\n' – currently you’ll end up with a rogue \r at the end of all lines other than the last one, which will mess up the results.

    Rather than using the Text property and then splitting it, you could just use the Lines property instead:

    string[] newLines = textBox1.Lines;
    string[] existingLines = textBox2.Lines;
    ...
    

    EDIT: As noted in Guffa’s answer, you will also want to avoid replacing textBox3.Text on each iteration. Personally I’d probably use create a List<string>, add to it on each iteration, then at the end use:

    textBox3.Lines = results.ToArray();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a simple Ruby program that I will run from
I'm trying to write a simple program that will receive a string of max
I'm trying to write a simple program that will compare the files in separate
I'm trying to write a simple high-low program that will output like this: $
The idea of my simple program that I've been trying to write is to
I am trying to write a simple program that lets me overlay a dot
I'm new to java and am trying to write a simple program that basicly
I'm trying to write a very simple program in C++ that finds the modulus
I am trying to write a simple VBS script that will create folders on
I'm trying to write a program that will delete a set of files/folders that

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.