BAT:〜字符串的语法

时间:2012-04-18 06:57:11

标签: string syntax batch-file

我看到BAT文件中常常使用':〜'符号,我认为它在一个位置有一个字符,但我找不到任何确认,也没有找到如何/何时使用它(它出现它也可以得到一个范围。

如果你能对此有所了解,谢谢。

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

还应该%% A:〜-1工作?或者我需要将其括在“”?

1 个答案:

答案 0 :(得分:1)

类型

help set 
在命令行中

,您将获得完整的说明。有些内容也在for命令的帮助中记录。因此help for会为您提供更多信息。

这是“help set”命令输出的一部分:

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.
相关问题