我有一些长达几百行的代码,我想找到每个“字符串”并将其替换为不同的“字符串”。以下是示例...
$BR360Button.Add_Click({BR360Button})
$BR368Button.Add_Click({BR368Button})
$BR370Button.Add_Click({BR370Button})
我想找到,({BR360按钮})并替换为{(新对象-Com WScript.Network).RemoveNetworkDrive(“M:”),(启动睡眠 1),(新对象-Com WScript.Network).MapNetworkDrive(“M:”,“\3600-co\data\store”)}
然后发现,({BR368按钮})并替换为{(new-object -Com WScript.Network).RemoveNetworkDrive("M:"),(start-sleep 1),(new-object -Com WScript.Network).MapNetworkDrive("M:", "\3680-co\data\store")}
然后发现,({BR370按钮})并替换为{(新对象-Com WScript.Network).RemoveNetworkDrive(“M:”),(启动睡眠 1),(新对象-Com WScript.Network).MapNetworkDrive(“M:”,“\3700-co\data\store”)}
如此反复,直到 900 行。我真的不想查找/替换 900 次。
有什么方法可以在 notepad++ 中轻松完成此操作?
提前致谢。
答案1
我想找到每个“字符串”并将其替换为不同的“字符串”
菜单“搜索”>“替换”(或Ctrl+ H)
将“查找内容”设置为
[\(][\{]BR(.*?)Button[\}][\)]
将“替换为”设置为
{(new-object -Com WScript.Network).RemoveNetworkDrive("M:"),(start-sleep 1),(new-object -Com WScript.Network).MapNetworkDrive("M:" , "\\\10-co\data\store")}
启用“正则表达式”
点击“全部替换”
前:
$BR360Button.Add_Click({BR360Button})
$BR368Button.Add_Click({BR368Button})
$BR370Button.Add_Click({BR370Button})
后:
$BR360Button.Add_Click{new-object -Com WScript.Network.RemoveNetworkDrive"M:",start-sleep 1,new-object -Com WScript.Network.MapNetworkDrive"M:" , "\3600-codatastore"}
$BR368Button.Add_Click{new-object -Com WScript.Network.RemoveNetworkDrive"M:",start-sleep 1,new-object -Com WScript.Network.MapNetworkDrive"M:" , "\3680-codatastore"}
$BR370Button.Add_Click{new-object -Com WScript.Network.RemoveNetworkDrive"M:",start-sleep 1,new-object -Com WScript.Network.MapNetworkDrive"M:" , "\3700-codatastore"}