powershell - Out-Gridview 去除下划线

标签 powershell out-gridview

考虑以下代码:

$a = @()

$b = "" |select ho_ho,ha_ha
$b.ho_ho = "1"
$b.ha_ha = "2"
$a+=$b

$b = "" |select ho_ho,ha_ha
$b.ho_ho = "3"
$b.ha_ha = "4"
$a+=$b

$a | Format-Table -AutoSize
$a | Out-GridView

使用 Format-Table,保留列标题上的下划线。

ho_ho ha_ha
----- -----
1     2
3     4

但是,使用Out-Gridview时,下划线会自动去掉?

Underscores removed

有谁知道如何避免这种情况?

最佳答案

这似乎与 WPF 中的事实有关,即文本中的第一个下划线作为控件加速器字符的前缀。

查看此 blog post详情:

WPF uses an underscore character instead of the ampersand character (like with WinForms) to prefix an access (a.k.a. accelerator or mnemonic) key in the text of its elements like Label and Button.

You can escape the underscore by using two underscores.

所以这段代码会在 gridview 中显示 Ok 但不会在 Format-Table 输出中显示

$a = @()

$b = "" |select ho__ho,ha__ha
$b.ho__ho = "1"
$b.ha__ha = "2"
$a+=$b

$b = "" |select ho__ho,ha__ha
$b.ho__ho = "3"
$b.ha__ha = "4"
$a+=$b

$a | Format-Table -AutoSize
$a | Out-GridView

请注意,转义仅适用于字符串中的第一个下划线,而不适用于其他下划线。

我认为这可能被视为一个错误(因为它实际上也没有添加任何快捷键),但我找不到关于 http://connect.microsoft.com 的任何报告。

关于powershell - Out-Gridview 去除下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41677950/

相关文章:

powershell - 管道循环到 out-gridview 并在每个循环上清除网格?

powershell - 检查字符串在PowerShell中是否包含数值?

powershell - 列出物理驱动器空间

node.js - npm 错误!文件 WindowsPowerShell\v1.0,而 Windows 7 上的 npm node-sass

performance - 提高我的 PowerShell 脚本的效率

powershell - Get-ADUser 整个林

Powershell CSV 变量到 Out-GridView