Solved

manipulate string collection using linq

Posted on 2013-11-04
4
818 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
  • 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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

813 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now