2016-05-06 25 views
3

有了這個批處理文件,我得到的輸出txt文件的每一行後面有個空格:回聲寫在批處理文件後間隔

@echo off 
setlocal enabledelayedexpansion 

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

我該如何去有關刪除尾隨空格?如果可能,我想避免創建一個新的批處理文件。

+0

@Dodekeract批處理文件已經[傳統技術在Windows(https://en.wikipedia.org/wiki/Windows_PowerShell)自2006年 - *十年,四,五個主要的Windows版本前*。不足爲奇的是,PowerShell擁有更多的字符串處理選項,例如'gc trimlist.txt |%{($ _ -split'=')[0] - 替換'3','。' } >> trimlist-new.txt' - 或者其他寫作方式。 – TessellatingHeckler

回答

3

字符串中包含%%A=之間的空格。爲了避免這種情況,您可以使用多行for循環,也可以簡單地在set語句中加上引號。

@echo off 
setlocal enabledelayedexpansion 

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