字符串替换在批处理文件 [英] String replacement in batch file

查看:116
本文介绍了字符串替换在批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以替换使用下面的命令在批处理文件中的字符串

We can replace strings in a batch file using the following command

set str="jump over the chair"
set str=%str:chair=table%

这些线做工精细,并切换到跳在桌子上串在椅子跳。现在我想用一些变量字符串中替换单词椅子,我不知道该怎么办了。

These lines work fine and change the string "jump over the chair" to "jump over the table". Now I want to replace the word "chair" in the string with some variable and I don't know how to do it.

set word=table
set str="jump over the chair"
??

任何想法?

推荐答案

您可以使用!,但你必须有ENABLEDELAYEDEXPANSION开关设置。

You can use !, but you must have the ENABLEDELAYEDEXPANSION switch set.

setlocal ENABLEDELAYEDEXPANSION
set word=table
set str="jump over the chair"
set str=%str:chair=!word!%

这篇关于字符串替换在批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆