2017-10-11 188 views
0

当我确定我的约会输出包含空格:摆脱空间

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. 

我怎样才能摆脱空间的?

回答

1

这是因为你添加的空间自己并没有从你的&符号隔离你的字符串。

For /F "Tokens=1-3Delims=/" %%A In ("%thedateis%") Do Set "day=%%A"&Set "month=%%B"&Set "year=%%C" 

编辑

你需要学习使用的最佳实践标记:

Set "variableName=variableValue" 
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%. 
+2

你需要还是学习的最佳实践经验,使用下面的符号:'设置“ thedateis = 11/12/2017“','Set”day = %% a“','Set”month = %% b“'和'Set”year = %% c“'。 – Compo