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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:07:11+00:00 2026-05-24T19:07:11+00:00

I want to compare 2 lines, but the one line is in a random

  • 0

I want to compare 2 lines, but the one line is in a random sequence. I use text boxes, like this:

Textbox1:
friends
pals
elephant

Textbox2:
aspl

Now when I hit a button I want Textbox3 to show the following:

Textbox3:
pals

What I got so far:

            Textbox3.Clear();
            string[] lines1 = Textbox2.Lines;
            foreach (string line1 in lines1)
            {
                string[] lines = Textbox1.Lines;
                foreach (string line in lines)
                {
                    if (line.Contains(line1))
                    {

                        Textbox3.Text += line;
                        Textbox3.Text += "\r\n";
                    }
                }

             }

But this will only copy the line to Textbox3 if the line in Textbox1 and Textbox2 is totally identical, not just if the characters is identical.

So my question is: How do I do that?

  • 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-24T19:07:11+00:00Added an answer on May 24, 2026 at 7:07 pm

    Simply sort the strings and compare the results assuming they are equal length and not null this works:

        private static bool IsPermutation(string one, string two)
        {
            var oneSorted = String.Join("", one.OrderBy(c => c).Select(x => x.ToString()).ToArray());
            var twoSorted = String.Join("", two.OrderBy(c => c).Select(x => x.ToString()).ToArray());
    
            return oneSorted == twoSorted;
        }
    

    EDIT: To answer the comment. Add that method to your class and replace the code inside your foreach with

    if (line.Length == line1.Length && IsPermutation(line, line1)) 
    {
       Textbox3.Text += line;
       Textbox3.Text += "\r\n";                    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file with my lines and I want to compare lines that
I want to compare the alpha channel from one image to ~1000 other images.
I want to append two text files together. I have one file with a
I want a diff output like - old line 1 + new line 1
I want to compare a column in table a and table b If the
I want to compare them: both of gems have advantages and disadvantages. For example
I want to compare count of operations of the sorting algorithms Merge Sort and
I want to compare two strings for equality when either or both can be
I want to compare the first few bytes in byte[] with a string. How
I want to compare records between 2 databases on my SQL 2008 Server. The

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.