Batch Script – Empty String
In this article, we are going to create an Empty String using Batch Script.
Batch Script :
@echo off set str1= set str2=Hello ::using if statement we will check that str1 is empty string or not. if [%str1%]== echo "str1 is an empty string" if [%str2%]== echo "str2 is an empty string" pause
- By using ‘ set ‘ we are getting our input string.
- str1 with no value (i.e Empty string)
- and str2 as ‘Hello’
- Now using the if statement we will check whether str1 is an empty string or not.
if [%str1%]== echo “str1 is an empty string” :: parenthesis is insecure always, so always use square brackets.
- A double colon (::) is used to add any comment in any batch script.
- Then we are using ‘pause’, to hold the screen until any key is pressed, so that we can read our output.
As we can clearly see that ‘str1 is an empty string’ is printed as output which means our if statement is True for the str1 argument. Hence str1 is an empty string.