Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

manipulate string collection using linq

Posted on 2013-11-04
4
Medium Priority
?
842 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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

824 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