Solved

manipulate string collection using linq

Posted on 2013-11-04
4
827 Views
Last Modified: 2016-02-10
I have a collection List<string>

Orders.Order_Details.Product.Supplier
Orders.Order_Details
Orders
Orders.Employee


how to format the data into like the following using linq or other method


Orders.Order_Details.Product.Supplier
Orders.Employee
0
Comment
Question by:eoswin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39622201
Your question is unclear. Are you asking how to filter the list to show just those items mentioned in the second half of your post? What "formatting" are you trying to accomplish?
0
 

Author Comment

by:eoswin
ID: 39622219
format is not the correct word.  it is like comparing each row with all other rows

because the 3rd value "Orders" and 2nd value "Orders.Order_Details"
exists in the 1st value "Orders.Order_Details.Product.Supplier"

and 4th value "Orders.Employee" does not exists in any other rows. i will be as it is.

so, results will be like this

Orders.Order_Details.Product.Supplier
Orders.Employee
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39622443
I believe this is what you are asking (though I'm still not 100% sure of that):

using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication178
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> collection = new List<string>()
            {
                "Orders.Order_Details.Product.Supplier",
                "Orders.Order_Details",
                "Orders",
                "Orders.Employee",
            };

            var query = from outer in collection
                        where !collection.Any(inner => inner.StartsWith(outer) && inner != outer)
                        select outer;

            foreach (var item in query)
            {
                Console.WriteLine(item);
            }

            Console.ReadKey();
        }
    }
}

Open in new window

0
 

Author Closing Comment

by:eoswin
ID: 39622459
thank you
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question