我正在尝试从变量中 grep 一些数据:
Select-String -inputObject $patternstring -Pattern $regex -AllMatches
| % { $_.Matches } | % { $_.Value } -OutVariable outputValue
Write-Host $outputValue
对于同一个 outvariable,我正在尝试进行字符串操作
$outputValue.Substring(1,$outputValue.Length-2);
这没有说明输出值 is an ArrayList
.
我怎样才能转换Arraylist
to String
?
正如 Sean_m 的评论中提到的,最简单的方法是首先使用 -join 运算符将 System.Collections.ArrayList 字符串转换为单个字符串:
$outputValue = $($outputValue -join [Environment]::NewLine)
完成此操作后,您可以对 $outputValue 执行任何常规字符串操作,例如 Substring() 方法。
上面我用一个新行分隔 ArrayList 中的每个字符串,因为这通常是 -OutVariable 在将字符串转换为 ArrayList 时分割字符串的字符串,但如果需要,您可以使用不同的分隔符/字符串。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)