Organize products into arrays

Hello,
I have a list of over 1,000 products that I would like to read line by line and put each product into an array.
for example all shirts into one array and all shoes into an array.. how can I do this?
Daniel SufreAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jacques Bourgeois (James Burger)PresidentCommented:
Where does that list comes from?

In what format is the data?

Are you in Visual Basic or C#?
Daniel SufreAuthor Commented:
they are all inside a ConcurrentDictionary in vb.net
Fernando SotoRetiredCommented:
What is the data structure of the products that are in the dictionary?
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Daniel SufreAuthor Commented:
the key ex: 598659659 then the name like "Shirt Blue Short Sleeves"
Fernando SotoRetiredCommented:
So your ConcurrentDictionary object is defined with a key of type integer and a value of type string something like this, ConcurrentDictionary<int, string>, is that correct?

Now the value having a type string with a value like this, "Shirt Blue Short Sleeves", so is the product type ALWAYS the first word in the string?
Daniel SufreAuthor Commented:
that's correct..
but if it makes things more simple I can make it Concurrent.ConcurrentDictionary(Of String, String())
and key=123456, value1=shirt, value2=brand and model
Fernando SotoRetiredCommented:
No need I just wanted to make sure where the product type was located in the Value string. Seeming that a List of objects is a type safe object would that be better for the collection of products? Seeming that you will be creating the collections at run time as per your statement, "put each product into an array. for example all shirts into one array and all shoes into an array", How will you be identifying each collection? Will you have predefined Array's/List to be filled? Or will you check the first entry and determine what type of list it is or something else.
Daniel SufreAuthor Commented:
i am okay with what makes things faster..
Fernando SotoRetiredCommented:
Hi Daniel;

The following code snippet should do what you need.
// The results of this Linq query is a dictionary with the 
// key as the product name and its value being a List<string> 
// with the complete product discription. The variable conDictionary
// is your ConcurrentDictionary<int, string> object.
Dictionary<string, List<string>> prodList = 
    (from prod in conDictionary.Values
     group prod by prod.Substring(0, prod.IndexOf(" ")) into prodGroup
     select prodGroup.Cast<String>().ToList()).ToDictionary(p => p[0].Substring(0, p[0].IndexOf(" ")));

// Look up a product in the dictionary and display all its products
string lookUpProduct = "Shirt3";
if( prodList.ContainsKey(lookUpProduct) )
    foreach (string prod in prodList[lookUpProduct])
        Console.WriteLine(prod);
else
    Console.WriteLine("Product {0} is not in the list of products", lookUpProduct);        

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.