我的.js文件如下:
var LoginData=([
{
"PL":"ccc","browser":"firefox","execute":"n",
},
{
"PL":"aaa","browser":"firefox","execute":"n",
},
{
"PL":"bbb","browser":"firefox","execute":"n",
},
{
"PL":"ddd","browser":"firefox","execute":"n",
]);
我需要搜索“PL”之类的字符串:“ccc”,“browser”:“firefox”,“execute”:“n” 并替换为“PL”:“ccc”,“browser”:“firefox”,“execute”:“y”。 我尝试使用replace命令,但它插入了????????可能是因为这是.js文件。
请让我知道它可行吗?
答案 0 :(得分:0)
通常这样的事情应该有效:
$filename = 'C:\path\to\your.js'
$srch = '"PL":"ccc","browser":"firefox","execute":"n"'
$repl = '"PL":"ccc","browser":"firefox","execute":"y"'
(Get-Content $filename) -replace $srch, $repl |
Set-Content $filename -Encoding ASCII