替換字符串考慮這個文件在PowerShell中使用正則表達式用單引號
AppConfig = {
version: '4.0.0',
clientId: "guid",
httpProxy: 'rest',
restUrl: "http://url.contoso.com/v1/",
conferences: ["lync", "hangouts", "webex"], // "lync", "hangouts", "webex"
dataRefreshInterval: 60 //seconds
}
我想用一個字符串替換單引號內的字符串。我想改變特定屬性的值(在我的例子中爲version
)。
$content = Get-Content $VersionFile
for($i = 0;$i -lt $content.Count; $i++)
{
if($content[$i] -like "*version:*")
{
$content[$i] = $content[$i] -creplace <replaceWhat>, <replaceWith>
}
}
更優雅的方式如何找到與version
行是讚賞。
@pandemic:如果你想替換單引號內的任何字符串,你必須爲每個替換都做這個,beca使用我猜想替換文本將不會是相同的每個項目 – Gawil