windows命令行:如何删除文件中的空格

时间:2010-07-14 01:57:09

标签: windows command-line

在linux中,我们可以使用tr命令删除空间。 我怎么能在Windows中做到这一点? 我喜欢从Windows XP的命令行中删除文本文件的每一行中的空格。 感谢。

3 个答案:

答案 0 :(得分:3)

这是来自http://www.dostips.com/DtTipsStringManipulation.php#Snippets.RemoveSpaces

的Windows shell脚本示例
set str=      word       &rem
echo."%str%"
set str=%str: =%
echo."%str%"

答案 1 :(得分:0)

你需要一种脚本语言(Powershell,Python,Perl ......)或者通过Cygwin使用tr。

答案 2 :(得分:0)

为什么不使用“SET filter =%*”来删除前导和尾随空格?

@ECHO Off

SET source=  1 2 3 4 5  
ECHO Source string = "%source%"
CALL :SpaceCut %source%
ECHO Beginning and ending spaces removed = "%filter%"

pause
exit /b

:SpaceCut
SET filter=%*
exit /b