- 1 year ago
How to concatenate 2 strings in .bat?
Comment
1 / 1
In a Windows batch script (.bat
), you can concatenate two strings by using the %
symbol to access the values of variables. Here's how you can concatenate two strings:
batch@echo off
setlocal
rem Define the two strings to concatenate
set "string1=Hello"
set "string2=World"
rem Concatenate the two strings
set "result=%string1%%string2%"
rem Display the result
echo %result%
endlocal
In this example, we define two variables string1
and string2
, each containing a string value. Then, we create a new variable called result
and concatenate string1
and string2
using the %
symbols around the variable names. The concatenated string is stored in the result
variable.
Finally, we echo the value of the result
variable to the console using echo %result%
.
Running the batch script will output:
HelloWorld
You can modify the values of string1
and string2
to concatenate different strings as needed. Remember that the %
symbols are used to access the values of variables in batch scripts.