0

我看到 BAT 文件中经常使用的 ':~' 符号,我认为它在某个位置获得了一个字符,但我找不到任何对此的确认,也找不到如何/何时使用它(它似乎可以得到范围)。

请您对此有所了解,谢谢。

SET STRING=C:\MyDocuments\
IF "%STRING:~-1%"=="\" SET STRING=%STRING:~0,-1%
ECHO String: %STRING%

%%A:~-1 也应该工作吗?还是我需要将它括在“”中?

4

1 回答 1

1

类型

help set 

在命令行中,您将获得完整的描述。有些也记录在for命令的帮助中。所以help for会给你额外的信息。

这是“帮助集”命令输出的一部分:

May also specify substrings for an expansion.

    %PATH:~10,5%

would expand the PATH environment variable, and then use only the 5
characters that begin at the 11th (offset 10) character of the expanded
result.  If the length is not specified, then it defaults to the
remainder of the variable value.  If either number (offset or length) is
negative, then the number used is the length of the environment variable
value added to the offset or length specified.

    %PATH:~-10%

would extract the last 10 characters of the PATH variable.

    %PATH:~0,-2%

would extract all but the last 2 characters of the PATH variable.
于 2012-04-18T07:02:37.100 回答