鉴于此变量
$foo = help | Select-String powershell
尝试拆分将失败
PS > $foo.split()
Method invocation failed because [Microsoft.PowerShell.Commands.MatchInfo]
does not contain a method named 'split'.
At line:1 char:1
+ $foo.split()
+ ~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
如何拆分此变量?
答案 0 :(得分:6)
匹配行的字符串值位于MatchInfo对象的Line属性中。
$foo.Line.split()
答案 1 :(得分:0)
Split是一个String方法,因此必须在字符串上调用它。
[string] $foo = help | Select-String powershell
或者
$foo = help | Select-String powershell | Out-String