Batch Script - Empty String



An empty string can be created in DOS Scripting by assigning it no value during its initialization as shown in the following example.

Set a=

To check for an existence of an empty string, you need to encompass the variable name in square brackets and also compare it against a value in square brackets as shown in the following example.

[%a%]==[]

The following example shows how an empty string can be created and how to check for the existence of an empty string.

Example

@echo off SET a= SET b=Hello if [%a%]==[] echo "String A is empty" if [%b%]==[] echo "String B is empty "

Output

The above command produces the following output.

String A is empty
batch_script_strings.htm
Advertisements