2012-04-18 40 views
0

我看到BAT文件中经常使用的':〜'符号,我认为它在某个位置获得了一个字符,但是我找不到对此的确认,也没有找到如何/何时使用它(看起来它也可以获得一个范围)。BAT:〜字符串的语法

请如果你能说出这一点,谢谢。

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

也应该%% A:〜-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. 
+0

谢谢!忘了帮助指令太哈哈 – user1229895 2012-04-18 07:07:52