Batch test if variable is equal to space

In my code, I am looping through every character in the string. I need to check if a character is a space.

This is my code:

if %str% == " " (
    ::echo Empty
    echo | set /p=%space%
    goto loopEnd
)

      

I've also tried:

if [%str%] == [" "] (
    ::echo Empty
    echo | set /p=%space%
    goto loopEnd
)

      

Both give error

( was unexpected at this time.

      

or

] was unexpected at this time.

      

I do not test errors for letters or numbers. What am I doing wrong?

Thank,

Zach

+3


source to share


1 answer


Try putting quotes around your variable.



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

      

+2


source







All Articles