Batch file Echo在批处理文件中写入尾随空间

Batch file Echo在批处理文件中写入尾随空间,batch-file,Batch File,使用此批处理文件,我在输出txt文件的每一行上都有一个尾随空格: @echo off setlocal enabledelayedexpansion for /f "delims==" %%A in (trimlist.txt) do set string=%%A & echo !string:,=.!>>trimlist-new.txt 如何删除尾随空格?如果可能的话,我希望避免创建新的批处理文件。字符串中包含%%a和=之间的空格。为了避免这种情况,您可以使用多行for

使用此批处理文件,我在输出txt文件的每一行上都有一个尾随空格:

@echo off
setlocal enabledelayedexpansion

for /f "delims==" %%A in (trimlist.txt) do set string=%%A & echo !string:,=.!>>trimlist-new.txt

如何删除尾随空格?如果可能的话,我希望避免创建新的批处理文件。

字符串中包含
%%a
=
之间的空格。为了避免这种情况,您可以使用多行
for
循环,或者在
set
语句周围加引号

@echo off
setlocal enabledelayedexpansion

for /f "delims==" %%A in (trimlist.txt) do set "string=%%A" & echo !string:,=.!>>trimlist-new.txt

@Dodekeract批处理文件从2006年开始使用——十年前,四到五个主要的Windows版本。毫不奇怪,PowerShell有更多的字符串处理选项,例如,
gc trimlist.txt |%{(${-split'=')[0]-replace'3','.}>>trimlist new.txt
-或其他各种编写方法。