Powershell Replace功能在替换时将逗号视为点

Eri*_*man 1 .net c# powershell scripting batch-file

所以我喜欢100个不同类型的文件,这些文件包含以下字符串:

1.2.0.0

1,2,0,0

我只是试图取代1.2.0.01.2.0.1,只有串用点,但PowerShell是也更换这些字符串1,2,0,01.2.0.0 为什么Powershell的治疗逗号状时期?

get-childitem $OUTPUT_PATH -recurse -include *.rc,*.cs,*.rtf,*.sql | 
select -expand fullname |
foreach {
  (Get-Content $_) -replace '1.2.0.0','1.2.0.1' | Set-Content $_
}
Run Code Online (Sandbox Code Playgroud)

Bil*_*art 5

-replace运营商使用正则表达式(见help about_Comparison_Operators).该.正则表达式中的意思是"的任何字符." 如果你的意思是文字.,你需要使用\,例如\..例如:

'abc 1.2.0.0 def' -replace '1\.2\.0\.0', '1.2.0.1'
Run Code Online (Sandbox Code Playgroud)

如果您不想使用正则表达式,请使用ReplaceString对象的方法.例如:

'abc 1.2.0.0 def'.Replace('1.2.0.0','1.2.0.1')
Run Code Online (Sandbox Code Playgroud)

两者都会输出abc 1.2.0.1 def.