批處理指令碼 - 刪除



字串替換功能也可用於從另一個字串中刪除子字串。

示例

@echo off 
set str = Batch scripts is easy. It is really easy. 
echo %str% 

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

上述程式中值得注意的關鍵內容是,使用 :’stringtoberemoved’ = 命令,從字串中刪除了單詞“is”。

輸出

上述命令會產生以下輸出。

Batch scripts is easy. It is really easy. 
Batch scripts easy. It really easy.
batch_script_strings.htm
廣告