我已經閱讀了將字符數組轉換爲PowerShell中的字符串的各種方法,但是它們都沒有處理我的字符串。 我的字符串的來源是:PowerShell將字符串轉換爲字符串
$ComputerName = "6WMPSN1"
$WarrantyURL = "http://www.dell.com/support/troubleshooting/au/en/aulca1/TroubleShooting/ProductSelected/ServiceTag/$ComputerName"
$WarrantyPage = Invoke-WebRequest -Uri $WarrantyURL
$WPageText = $WarrantyPage.AllElements | Where-Object {$_.id -eq "TopContainer"} | Select-Object outerText
產生的WPageText是一個字符數組,所以我不能使用選擇串-pattern「天」 -Context
我已經試過:
$WPageText -join
[string]::Join("", ($WPageText))
按 http://softwaresalariman.blogspot.com.au/2007/12/powershell-string-and-char-sort-and.html
唯一的事情,我已經成功與迄今:
$TempFile = New-Item -ItemType File -Path $env:Temp -Name $(Get-Random)
$WPageText | Out-File -Path $TempFile
$String = Get-Content -Path $TempFile
除了寫入和讀取文件之外,還有什麼辦法可以做到這一點?
++爲$ OFS信息;值得推薦_localizing_'$ OFS'的變化,例如:'&{$ OFS =''; 「$ c」}'。請注意,即使_effective_默認爲單個空格,默認情況下,_variable_「$ OFS」是_not defined_。不確定你在推薦關於字符串構造函數的東西; '$ result = $ a'做同樣的事情更加簡單和高效。 – mklement0