Compo's IF solution with find/replace is probably the simplest and best performing method.
But FOR /F might be a good solution if you need to parse the value. For example, the default delims of space will effectively trim leading and trailing spaces.
FOR /F will not iterate a string if it is empty or contains only spaces/tabs. The EOL option should be set to space so that lines beginning with ; are not falsely missed (thanks Stephan for your comment). So if you want to do something with non-empty, but nothing upon empty (or blank), then
for /f "eol= " %%A in ("%VAR%") do (
echo VAR is defined and contains more than just spaces or tabs
)
If you want to take action upon empty (or space value), then you can take advantage of the fact that FOR /F returns a non-zero value if it does not iterate. You must enclose the entire FOR construct in parentheses to properly detect the empty condition. And you should make sure the last command of the DO clause always returns 0.
(
for /f "eol= " %%A in ("%VAR%") do (
echo VAR is defined and contains more than just spaces or tabs
rem Any number of commands here
(call ) %= A quick way to force a return code of 0. The space after call is critical =%
)
) || (
echo VAR is not defined or contains only spaces/tabs
)