Solved

manipulate string collection using linq

Posted on 2013-11-04
4
808 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 74

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 74

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 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

18 Experts available now in Live!

Get 1:1 Help Now