Batch test if variable is equal to a space

batch-file, windows

Solution

Try putting quotes around your variable.

if "%str%" == " " (
    ...
)

Problem

In my code, I am looping through each character in a string. I need to test if the character is a space. This is my code: ``` if %str% == " " ( ::echo Empty echo | set /p=%space% goto loopEnd ) ``` I have also tried: ``` if [%str%] == [" "] ( ::echo Empty echo | set /p=%space% goto loopEnd ) ``` Both give the error ``` ( was unexpected at this time. ``` Or ``` ] was unexpected at this time. ``` I don't get errors testing for letters or numbers. What am I doing wrong? Thanks, Zach

Original source

Related problems