Create a list of paired string values in PowerShell

Question:

For a project I am doing, I need to check and see if a pair of strings are present in a line from a file.

I have tried to use a hash table like this:

This works well until I try to insert a duplicate make. I quickly found out that hash tables do not accept duplicates.

So is there a way of creating a double list of strings in PowerShell? It is very easy to do in C# , but i have found no way of achieving it in PowerShell.

Answer:

With minimal changes to your code and logic:

This uses custom psobject, cast to an array so that += is allowed.

Source:

Create a list of paired string values in PowerShell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply