if 语句中的空格

Spaces in a if statement

我似乎无法让 if 语句为 Hello World 工作。我认为这是因为空间的原因,但我们将不胜感激。

if %A%==Chrome (
    start "" "C:\Users\Matthew\Appdata\Local\Google\Chrome\Application\chrome.exe\"
) else (
    if %A%==Steam (
        start "" "C:\Program Files (x86)\Steam\Steam.exe\"
    ) else (
        if %A%==CMD (
            start
        ) else (
            if %A%==System32 (
                start "" "C:\Windows\System32\"
            ) else (
                if %A%==Appdata (
                    start "" "C:\Users\Matthew\Appdata\"
                ) else (
                    if %A%==Skype (
                        goto Skype
                    ) else (
                        if "%A%"=="Hello World" (
                            goto HelloWorld
                        )
                    )   
                )
            )           
        )
    )
)

如果 %A% 的内容包含空格 (Hello world),第一个条件将失败,因为它将被解析为

if Hello World==Chrome (

如果您希望变量中有空格,则需要在所有条件中而不是在最后一个条件中使用引号

if "%A%=="Chrome" (
    start "" "C:\Users\Matthew\Appdata\Local\Google\Chrome\Application\chrome.exe\"
) else if "%A%"=="Steam" (
    start "" "C:\Program Files (x86)\Steam\Steam.exe"
) else if "%A%"=="CMD" (
    start
) else if "%A%"=="System32" (
    start "" "C:\Windows\System32\"
) else if "%A%"=="Appdata" (
    start "" "C:\Users\Matthew\Appdata\"
) else if "%A%"=="Skype" (
    goto Skype
) else if "%A%"=="Hello World" (
    goto HelloWorld
)