当我定义我的日期时,输出包含空格:
set thedateis=20/10/2017
for /F "tokens=1,2,3 delims=/" %%a in ('echo %thedateis%') do set day=%%a & set month=%%b & set year=%%c
echo The chosen date is: %thedateis%, Day:.%day%., Month:.%month%., Year:.%year%.
它给了我
The chosen date is: 20/10/2017, Day:.20 ., Month:.10 ., Year:.2017.
如何摆脱空间?
答案 0 :(得分:1)
这是因为你自己添加了空格,并没有将你的字符串与你的&符号隔离开来。
For /F "Tokens=1-3Delims=/" %%A In ("%thedateis%") Do Set "day=%%A"&Set "month=%%B"&Set "year=%%C"
修改强>
您需要学会使用以下最佳实践符号:
Set "variableName=variableValue"
答案 1 :(得分:0)
这是解决方案(感谢@LS_ᴅᴇᴠ)并且效果非常好:
set thedateis=11/12/2017
for /F "tokens=1,2,3 delims=/ " %%a in ('echo %thedateis%') do (
set day=%%a
set month=%%b
set year=%%c
)
echo The chosen date is: %thedateis%, Day:.%day%., Month:.%month%., Year:.%year%.