在一个文件中,我有这样一行:
I have lot of spaces in me.
我使用以下PowerShell代码将每个空格替换为一个空格:
$String = "I have lot of spaces in me."
while ($String.Contains(" "))
{
$String = $String -replace " "," "}
结果如下:
我里面有很多空格。
我想对文本文件中的每一行都这样做。你能告诉我最好的方法吗?
第二部分:
当有多个空格时,我该如何仅替换其中的某些内容,例如用;
替换?
回复如下:
;4828;toto;toto;Ticket;0112APPT
而不是:
;4828;toto toto;Ticket;0112APPT
明确一下,我只想用字符;
替换两个空格。