Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.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
Batch file 从批处理变量中删除最后一个字符_Batch File - Fatal编程技术网

Batch file 从批处理变量中删除最后一个字符

Batch file 从批处理变量中删除最后一个字符,batch-file,Batch File,我有一个名为version的批处理变量,其值为“2930.2323” 现在我想删除最后一个字符(或所有空格)。我两种方法都试过了,但空格没有删除 // MYVAR is set at the beginning of my batch file by another source code SET "MYVAR=%MYVAR: =%" 您的代码不会删除“空白”,而只删除空格(即如果它是一个选项卡,则不会删除它,除非您添加另一行来删除选项卡) 对于给定的字符串,我建议另一种方法: for %%a

我有一个名为version的批处理变量,其值为“2930.2323”

现在我想删除最后一个字符(或所有空格)。我两种方法都试过了,但空格没有删除

// MYVAR is set at the beginning of my batch file by another source code
SET "MYVAR=%MYVAR: =%"
您的代码不会删除“空白”,而只删除空格(即如果它是一个选项卡,则不会删除它,除非您添加另一行来删除选项卡)

对于给定的字符串,我建议另一种方法:

for %%a in (%myvar%) do set "myvar=%%a"
echo --%myvar%--
注意:这只适用于字符串开头或结尾的空格。字符串中间的一个空间将字符串分成两个(或更多)。此外,一些特殊字符也会有问题。但是它可以处理像您的示例(“版本号”)这样的字符串