【问题标题】:Batch file find string in string批处理文件在字符串中查找字符串
【发布时间】:2012-05-15 11:15:54
【问题描述】:

在批处理文件中,我想查看 %1 是否在集合中。

例如,作为替代

if %1 equ /? goto help
if /I %1 equ -? goto help
if /I %1 equ /help goto help
etc

看起来应该很简单,但我无法让它工作。我尝试过使用和不使用 FOR 循环和 search:string。

【问题讨论】:

    标签: batch-file cmd environment-variables


    【解决方案1】:
    @echo off
    setlocal enabledelayedexpansion
    set "helpoptions=@/?@-?@/help@"
    if not "!helpoptions:@%~1@=!"=="%helpoptions%" goto help
    goto :eof
    :help
    echo Help
    

    会是一个选择,虽然不是很漂亮。

    【讨论】:

    • 确实如此。也可以使用空格作为分隔符,这样可以减少混乱,但可能会掩盖一些不明显的错别字。
    猜你喜欢
    • 2016-02-25
    • 2011-10-23
    • 1970-01-01
    • 2022-01-10
    • 2021-11-25
    • 1970-01-01
    • 2022-08-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多