Windows 10

How To Compare Strings In Batch Files

In this tutorial, we are going to see how to compare strings in batch files using the == operator. The batch file contains a series of DOS (Disk Operating System) instructions. It allows triggering the execution of commands found in this file.
 

How To Compare Strings In Batch Files

The following example compare two strings and display if they are equal or not:

@echo off
SetLocal EnableDelayedExpansion

set var1=Hello
set var2=Hello
set var3=HELLO

if !var1! == !var2! echo Equal

if !var1! == !var3! (echo Equal) else (echo Not Equal)

Output:

Equal
Not Equal

 

Leave a Reply

Your email address will not be published. Required fields are marked *