【问题标题】:Windows batch file - Loop through array of date range then split each itemWindows 批处理文件 - 循环遍历日期范围数组,然后拆分每个项目
【发布时间】:2016-11-03 17:23:30
【问题描述】:

我想从数组中遍历特定的日期范围。 每个项目都有由空格分隔的开始日期和结束日期。 下面是我的代码,但我无法正确打印拆分部分。它只打印 string1=

我错过了什么?提前致谢。

SET dates[0]=01/01/2016 02/01/2016
SET dates[1]=03/01/2016 04/01/2016

set "x=0"

:SymLoop
if defined dates[%x%] (
    rem echo !dates[%x%]!
    set "str=!dates[%x%]!"

    echo !str!  

    set "string1=%str: =" & set "string2=%"

    echo string1=%string1%
    echo string1=%string2%

    set /a "x+=1"
    GOTO :SymLoop
)

【问题讨论】:

  • 在添加标签之前阅读标签信息!我很确定标签 dosms-dos 在这里不适用(除非你真的在使用 1980 年代的这个操作系统)!
  • @aschipfl 授予。

标签: loops batch-file cmd


【解决方案1】:

您正在使用延迟扩展(我猜您的原始代码中有setlocal enabledelayedexpanion),但忘记了以下两行:

echo string1=%string1%
echo string1=%string2%

将它们更正为:

echo string1=!string1!
echo string1=!string2!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-30
    • 1970-01-01
    • 1970-01-01
    • 2010-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多