Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String BAT:~字符串的语法_String_Syntax_Batch File - Fatal编程技术网

String BAT:~字符串的语法

String BAT:~字符串的语法,string,syntax,batch-file,String,Syntax,Batch File,我看到在BAT文件中经常使用“:~”符号,我想它在某个位置上会得到一个字符,但我找不到任何关于这一点的确认,也找不到如何/何时使用它(它似乎也能得到一个范围) 请你解释一下,谢谢 SET STRING=C:\MyDocuments\ IF "%STRING:~-1%"=="\" SET STRING=%STRING:~0,-1% ECHO String: %STRING% %%A:~-1是否也可以工作?或者我需要用“”括起来吗?类型 help set 在命令行中,您将获得完整的描述。在fo

我看到在BAT文件中经常使用“:~”符号,我想它在某个位置上会得到一个字符,但我找不到任何关于这一点的确认,也找不到如何/何时使用它(它似乎也能得到一个范围)

请你解释一下,谢谢

SET STRING=C:\MyDocuments\
IF "%STRING:~-1%"=="\" SET STRING=%STRING:~0,-1%
ECHO String: %STRING%
%%A:~-1是否也可以工作?或者我需要用“”括起来吗?

类型

help set 
在命令行中,您将获得完整的描述。在
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.