Batch - Search if a variable contains spaces
batch-file
Solution
This should do as you need: double quotes are always the solution for spaces, and also with some other characters.
if not "%VAR%"=="%VAR: =%" exit 1
Problem
I have a variable that I need to check if it contains spaces, and exit if it does. I have this code: ``` if not [%VAR%]==[%VAR: =%] exit 1 ``` .. but it does not work for spaces. I can use it for other characters though. For example looking for "/" works with same code: ``` if not [%VAR%]==[%VAR:/=%] exit 1 ``` Is there a way to do it? Thanks,