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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:53:25+00:00 2026-06-12T14:53:25+00:00

I have two list : (Note: List’s Items are combination of NAME & ID

  • 0

I have two list : (Note: List’s Items are combination of “NAME” & “ID” )

List<string> ListA = new List() {"SAM001","SAM002","SAM003","PIT001","PIT002","PIT004","ROSE001","ROSE002","JASE001" };
//so on

List<string> ListB = new List() {"SAM001","SAM003","PIT000","ROSE002","JASE001","INDI000"};` 
//so on...

Now Based on these two list i want to create two new list suppose listCommon & listUncommon.

listCommon will contain all matched items of ListA & ListB.

listUnCommon will contain all remaining items of ListA

Now My condition is if Any item in ListB has NAME + 000 then all the items of ListA starting with that Name should add in my listCommon.

Example 1 : if ListB item is PIT000 and ListA item are PIT001,PIT002,PIT003,ABC001
then listCommon = PIT001,PIT002,PIT003 because ListB has PIT with 000 so condition true all ListA ‘PIT’ items added in listcommon

So as above list and my condition i want my final list below

List<string> listCommon = new List() {"SAM001","SAM003", "PIT001","PIT002","PIT004","ROSE002", "JASE001" };
List<string> listUncommon = new List() {"SAM002", "ROSE001"};

Please suggest..i just spend my couple of minutes in loops but not getting actual result as i mentioned 🙁

  • 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-12T14:53:27+00:00Added an answer on June 12, 2026 at 2:53 pm

    This should work.

    var common = ListA.Intersect(ListB)
        .Concat(
            ListA.Where(a => 
                 ListB.Any(
                    b => b.EndsWith("000") && 
                    b.StartsWith(a.Substring(0, a.Length - 3))
                 )
            )
        );
    var uncommon = ListA.Except(common);
    

    Using an insersect, then you are selecting any from list A where list B has an entry that matches the first 3 letters and ends with 000.

    This is not the most efficient way of doing this, however it is terse code-wise.

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

Sidebar

Related Questions

I have two list: set lista {5 6} set listb {8 9} and the
Question is simple: I have two List List<String> columnsOld = DBUtils.GetColumns(db, TableName); List<String> columnsNew
i have two lists: List<comparerobj> list_c = new List<comparerobj>(); List<comparerobj> list_b = new List<comparerobj>();
I have two complex dictionaries in the form Dictionary<string, Dictionary<string, Dictionary<string, List<string>>>> So as
I have two List<string> ( listOfFullPaths containg full database paths for e.g. C:\MyDir\SomeDir\SomeDatabase.mdf) and
I have two list containing List<MyObj>. and MyObj has a String ID member. I
I have two complex (i.e. objects with string, int, double, List and other home
I have two List s of type int where I store point coordinates called
I have two list: list_a = [<User: x>, <User: y>] list_b = [False, True]
I have two list on my request on jsp. First one is productGroupName, and

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.