Solved

manipulate string collection using linq

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

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 …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

821 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