如何在字符串操作中使用变量?又如何以其他方式引用变量

时间:2018-04-02 10:11:49

标签: string batch-file

我有一个批处理文件可以帮助我进行字符串操作。它作为插件/功能。问题是,我不知道如何在字符串操作中使用变量。

以下是我遇到问题的代码:

set result=%_unstring:%_charstoreplace%=%_replacementchars%

变量_unstring_charstoreplace_replacementchars都是参数。

如何在操纵%_unstring%时使用变量?

1 个答案:

答案 0 :(得分:1)

SET "unstring=some string containing stuff"
SET "charstoreplace=ing cont"
SET "replacementchars=with this"

CALL SET "result=%%unstring:%charstoreplace%=%replacementchars%%%"
SET result

可能是最简单的。它依赖于批处理使用的解析方法。