我有一個字串:
<UserInputs>/span>< UserInputs Question="Groupname" Answer="& lt;Values Count="1"&。 gt;<Value DisplayName="AllHummanresources&。 quot; Id="af05c5d3-2312-c897-8439-08979d4d0a49& quot; />< /Values>" Type="System. SupportingItem.PortalControl.InstancePicker InstancePicker" />< UserInput Question="Ausgabe"/span> 答案="Namen" 型別="richtext" /> </UserInputs>
我想修剪字串,以獲得"AllHummanresources"作為結果。所以我需要在DisplayName="和"之間的字。
我怎樣才能實作這個目標? 我在網上沒有找到一個合適的例子:(
)問候
uj5u.com熱心網友回復:
你可以使用-replace運算子,這樣你就可以省略除該字串之外的所有內容。
$string -replace '. (?:DisplayName=")(.*?)". ', '$1'/code>
這只和你的輸入字串的一致性一樣好。
uj5u.com熱心網友回復:
你可以使用Select-String Cmdlet以及與regex。
$result = $your_string| Select-String -Pattern "DisplayName=& quot;(. *?)""
如果匹配成功,你可以通過訪問該組。
Write-Host $result. Matches.Groups[1].Value。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/326677.html
標籤:
