替换字符串考虑这个文件在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