我的
Windows批处理文件中有以下字符串:
"-String"
该字符串还包含字符串开头和结尾的两个引号,如上所述.
我想剥离第一个和最后一个字符,以便我得到以下字符串:
-String
我试过这个:
set currentParameter="-String" echo %currentParameter:~1,-1%
这将打印出应该是的字符串:
-String
但是当我尝试像这样存储编辑过的字符串时,它会失败:
set currentParameter="-String" set currentParameter=%currentParameter:~1,-1% echo %currentParameter%
什么都没打印出来.我做错了什么?
这真的很奇怪.当我删除这样的字符时,它可以工作:
set currentParameter="-String" set currentParameter=%currentParameter:~1,-1% echo %currentParameter%
打印出来:
-String
但实际上我的批次有点复杂,并且它不起作用.我将展示我编程的内容:
@echo off set string="-String","-String2" Set count=0 For %%j in (%string%) Do Set /A count+=1 FOR /L %%H IN (1,1,%COUNT%) DO ( echo . call :myFunc %%H ) exit /b :myFunc FOR /F "tokens=%1 delims=," %%I IN ("%string%") Do ( echo String WITHOUT stripping characters: %%I set currentParameter=%%I set currentParameter=%currentParameter:~1,-1% echo String WITH stripping characters: %currentParameter% echo . ) exit /b :end
输出是:
. String WITHOUT stripping characters: "-String" String WITH stripping characters: . . String WITHOUT stripping characters: "-String2" String WITH stripping characters: ~1,-1 .
但我想要的是:
. String WITHOUT stripping characters: "-String" String WITH stripping characters: -String . . String WITHOUT stripping characters: "-String2" String WITH stripping characters: -String2 .