我打赌有人可以快速帮助我,没有找到正确的答案/解决方案而不是搜索功能,现在已经花了很多时间用于简单的单行班轮。我需要使用批处理文件在其中创建一个searchlist变量和多个搜索元素。 例如:
@Echo Off
Setlocal EnableDelayedExpansion
set searchlist="_Var1","_Var 2","Var_ 3","File1","varwithspaces = 12","supervar ="
FOR %%R IN (%searchlist%) DO (
echo %%R
)
pause
输出是:
"_Var1"
"_Var 2"
"Var_ 3"
"File1"
"varwithspaces = 12"
"supervar ="
但我需要这个输出:
_Var1
_Var 2
Var_ 3
File1
varwithspaces = 12
supervar =
请帮助我,即时批处理...
答案 0 :(得分:0)
您实际上可以使用已设置的enabledelayedexpansion
。然后将%%r
设置为变量,然后替换"
@Echo Off
Setlocal EnableDelayedExpansion
set searchlist="_Var1","_Var 2","Var_ 3","File1","varwithspaces = 12","supervar ="
for %%r in (%searchlist%) DO (
set "var=%%r"
set "var=!var:"=!"
echo !var!
)
endlocal
pause
然后,为了摆脱双引号而不使用子字符串替换,只需使用变量前面的~
。
@Echo Off
set searchlist="_Var1","_Var 2","Var_ 3","File1","varwithspaces = 12","supervar ="
for %%r in (%searchlist%) DO (
echo %%~r
)
pause
答案 1 :(得分:0)
@elzooilogico 在评论中说:只需使用echo %%~R
@Echo Off
set searchlist="_Var1","_Var 2","Var_ 3","File1","varwithspaces = 12","supervar ="
FOR %%R IN (%searchlist%) DO (
echo %%~R
)
pause
An A-Z Index of the Windows CMD command line - 与Windows cmd相关的所有内容的绝佳参考。
For /? - 有条件地多次执行命令。 Command Line arguments (Parameters)