所以,我有以下命令:獲取內容替換滿弦
(Get-Content $path).Replace($current, $new) | Set-Content $path
它正常工作,改變一個字符串,但可以說我有在$path
以下字符串:"This is a test. testing was done."
如果我設置$current
至"test"
和$new
至"Blah"
。我會得到"This is a Blah. Blahing was done."
我如何使它只改變"test"
而不是"testing"
所以我的字符串將是:"This is a blah. testing was done."
?
假設$ current被傳遞給腳本。我如何將「\ b」添加到開始和結束?我試着用「+」和其他一些變體添加它,但它似乎不起作用。 – Paulo
我不太明白 - 你能告訴我代碼嗎? – Itchydon
param( [string] $ path =「」, [string] $ new =「」, [string] $ current =「」) (Get-Content $ path).Replace($ current,$ new) | Set-Content $ path – Paulo