批處理刪除所有空格

這用於通過替換刪除字串中的所有空格。

示例

@echo off
set str=This string    has    a  lot  of spaces
echo %str%

set str=%str:=%
echo %str%

關於上述程式的關鍵是,:=操作符用於從字串中刪除所有空格。

以上命令產生以下輸出。

This string    has    a  lot  of spaces
Thisstringhasalotofspaces

上一篇: 批處理字串 下一篇: 批處理數組