无涯教程-批处理 - Replace a String函数

52 阅读1分钟

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

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.

参考链接

www.learnfk.com/batch-scrip…