Home > Blockchain >  How do I store this set of parameters in an array and then output it?
How do I store this set of parameters in an array and then output it?

Time:11-24

Basically, I need to add a few parameters into an array to store them and then output them with " (Nameof parameter) Count:" in front of them. I'm just confused on how to actually do this.

The parameters have used a loop to go through a file and count the amount of times a certain word is present.

The names are $Hi $Bye $Yes $No

I was thinking it would just be

                          $Array = @($Hi, $Bye, $Yes, $No)
                                $Array[0]
                                $Array[1], etc...

But then how do I actually put "(Name of parameter) Count:" in front of it?

If there is a better way to do this, I am open to suggestions! I am new to powershell, so thank you in advance.

CodePudding user response:

With an array you would need to exclusively name it. So for your Output you'd just hardcode it like this:

Write-Output "Hi Count: $Array[0]"

Using a hash table might be more like what you're looking for.

$ht = @{"Hi" = $Hi; "Bye" = $Bye; "Yes" = $Yes; "No" = $No}

If you just output the hash table you will ge an output that is just missing the "Count". If you need that you could use $ht.GetEnumerator() and a For-Each loop. That way you will have $_.Key and $_.Value available.

  • Related