【发布时间】:2023-03-13 04:16:01
【问题描述】:
在 Windows 批处理文件中,以下内容将提取除最后 4 个字符之外的所有 %1:
set foo=%1
set x=%foo:~,-4%
但这不起作用:
set x=%1:~,-4%
这是为什么?
【问题讨论】:
-
它们不是同一类型的变量,
%1甚至没有与%foo%相同的格式,这本身应该是一个赠品。顺便说一句,为了安全和可读性,它应该读作set "foo=%~1"和set "x=%foo:~0,-4%"。
标签: string windows batch-file variables environment-variables