from another application I have key-value pairs which I want to use in my script.
But there they have e.g. the keys "a" and "A" - which causes an Error double keys aren't allowed.
$x = @{ "a" = "Entry for a"; "A" = "S.th.else for A" }
What can I do as I would need both or none?
Thanks in advance,
Gooly
To remove the Key-value from the Hashtable, you need to use the Remove(Key) method. You cannot remove the hashtable entry with the values. You must use the key inside the Remove() method.
Actually a Map (whether it is a HashTable, HashMap or whatever) can have duplicate values, but not duplicate keys.
The key/value pairs might appear in a different order each time that you display them. Although you cannot sort a hash table, you can use the GetEnumerator method of hash tables to enumerate the keys and values, and then use the Sort-Object cmdlet to sort the enumerated values for display.
Adding values of the hash table is simple as the adding string. We just need to use the addition operator (+) to merge two hash table values.
By default PowerShell Hash tables are not case sensitive. Try this
$h = new-object System.Collections.Hashtable
$h['a'] = "Entry for a"
$h['A'] = "S.th.else for A"
$h[0] = "Entry for 0"
$h[1] = "Entry for 1"
$h
Or this (depending on the syntax that you prefer)
$hash = New-Object system.collections.hashtable
$hash.a = "Entry for a"
$hash.A = "S.th.else for A"
$hash.0 = "Entry for 0"
$hash.1 = "Entry for 1"
$hash.KEY
$hash
You can create a case-sensitive powerhsell hash table using System.Collections.Hashtable
$x = New-Object System.Collections.Hashtable
$x['a']="Entry for a"
$x['A']="S.th.else for A"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With