简体   繁体   English

PowerShell替换具有双引号的字符串

[英]PowerShell to replace string having double quotes

I have a file and I want to replace below line in file with blank string 我有一个文件,我想用空白字符串替换文件下面的行

 optionsBuilder.UseSqlServer(@"Server=(localdb)\sql2016;Initial Catalog=psdb;Integrated Security=SSPI");

below PowerShell code is doing nothing. 下面的PowerShell代码无所作为。 please advise 请指教

(Get-Content $fileName2) -replace "^optionsBuilder.UseSqlServer.*$", "a" | Set-Content $fileName2

The string you want to replace has a leading space. 您要替换的字符串前面有一个空格。 Is that intentional? 那是故意的吗? thanks @ansgar 谢谢@ansgar

i changed to ^* and it worked. 我更改为^ *,并且有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM