Reputation: 149
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
Upvotes: 7
Views: 3378
Reputation: 9319
Try putting quotes around your variable.
if "%str%" == " " (
...
)
Upvotes: 5