批處理指令碼 - 替換字串



若要將子字串替換為另一字串,請使用字串替換特徵。

示例

@echo off 
set str=This message needs changed. 
echo %str% 

set str=%str:needs=has% 
echo %str%

上述程式的關鍵之處是,該示例透過語句 %str:needs = has% 替換單詞“needs” 為字串“has”。

輸出

上述命令生成以下輸出。

This message needs changed. 
This message has changed.
batch_script_strings.htm
廣告
© . All rights reserved.