要将子字符串替换为另一个字符串,请使用字符串替换功能。

Replace a String - 示例

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

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

关于上述程序,需要注意的关键是,该示例通过语句%str:needs=has%用字符串" has"替换了" needs"一词。

上面的命令产生以下输出。

This message needs changed. 
This message has changed.

参考链接

https://www.learnfk.com/batch-script/batch-script-replace-string.html