PowerShell哈希表双键错误:"a";和"A"表示 [英] PowerShell Hash Tables Double Key Error: "a" and "A"

查看:66
本文介绍了PowerShell哈希表双键错误:"a";和"A"表示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从另一个应用程序中,我有一些要在脚本中使用的键值对.
但是他们有例如不允许使用键"a"和"A"-导致错误的双键.

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

推荐答案

默认情况下,PowerShell哈希表不区分大小写. 试试这个

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

这篇关于PowerShell哈希表双键错误:"a";和"A"表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆