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

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

问题描述

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

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

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

这些行工作正常并将字符串跳过椅子"更改为跳过桌子".现在我想用一些变量替换字符串中的chair"这个词,但我不知道该怎么做.

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天全站免登陆