我有字串"url": "https://maven.fabricmc.net/net/fabricmc/fabric-installer/0.11.0/fabric-installer-0.11.0.jar"。我想從字串中洗掉所有內容,除了https://maven.fabricmc.net/net/fabricmc/fabric-installer/0.11.0/fabric-installer-0.11.0.jar(我也想洗掉引號)。
我該怎么做?
uj5u.com熱心網友回復:
$str = """url"": ""https://maven.fabricmc.net/net/fabricmc/fabric-installer/0.11.0/fabric-installer-0.11.0.jar"""
$str.Split(""": """)[1].Replace("""","")
uj5u.com熱心網友回復:
我能想到的最短的可能有不正確的索引號,只是測驗切換'3'
( $str -split """ )[3]
uj5u.com熱心網友回復:
您可以使用-replace運算子并提取所需的部分。
'"url": "https://maven.fabricmc.net/net/fabricmc/fabric-installer/0.11.0/fabric-installer-0.11.0.jar"' -replace '"url": "(. )"','$1'
但是,由于這似乎是 JSON 格式,您最好ConvertFrom-Json在整個事物上使用,然后通過點符號訪問該屬性。
這比嘗試正則運算式或字串匹配 JSON 的部分要容易一些。
$converted = Get-Content file.json | ConvertFrom-Json
$converted.url
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/487512.html
標籤:电源外壳 powershell-7.0 PowerShell-7.2
上一篇:將字串變數轉換為整數
下一篇:獲取未壓縮的zip大小
