The Wayback Machine - https://web.archive.org/web/20240717024817/https://www.geeksforgeeks.org/batch-script-string-concatenation/
Open In App

Batch Script – String Concatenation

Last Updated : 28 Nov, 2021
Improve
Suggest changes
Post a comment
Like Article
Like
Save
Share
Report

String Concatenation is combining two or more strings to create a new string. For instance, let a string “Good” and take another string “Morning” now by string concatenation i.e. “Good” + “Morning” and we got new string i.e. “Good Morning”. This is string concatenation.

Let see some examples of string concatenation using batch script.

Example 1 :

In this example, we concatenate two strings.

First, we create a batch file named “concatenation.bat” and open it in notepad.

@echo off
:: We take two string Good and Morning
set str1=Good
set str2=Morning
:: Below command will join two string and store it in str_new variable
set str_new=%str1% %str2%
echo %str_new%
pause

Save the above batch script and run it.

Note:  “pause” is used to hold the screen of the executed file until any key is pressed.

Output : 

Good Morning

Example 2 :

In this example, we concatenate more than two strings.

First, open the notepad and write the following command.

@echo off
:: Here we take three string
set str1=Hello Dear
set str2=Welcome to Geeks For Geeks site
set str3=This is example of string Concatenation
:: Below command will join these strings and store it in str_new variable
set str_new=%str1% %str2% and %str3%
echo %str_new%
pause

Save the above batch script with the .bat extension and run it.

Output : 

Hello Dear Welcome to Geeks For Geeks site and This is example of string Concatenation

Above in both examples, we see how to concatenate string using batch script.



Similar Reads

Batch Script - How to check if a process is running via a Batch Script
Given a process or application (.exe) file, the task is to create a batch script that checks whether the process is running or not and output the same. Example: In this example, we have created a batch script by the name process.bat. We can easily check whether a process is currently running or not using the tasklist toolkit. Tasklist allows us to
2 min read
Bash Script - Difference between Bash Script and Shell Script
In computer programming, a script is defined as a sequence of instructions that is executed by another program. A shell is a command-line interpreter of Linux which provides an interface between the user and the kernel system and executes a sequence of instructions called commands. A shell is capable of running a script. A script that is passed to
3 min read
Batch Script - Replace a String
In this article, we are going to Replace a substring with any given string. Batch Script :@echo off set str=GFG is the platform for geeks. echo %str% set str=%str:the=best% echo %str% pause In the above example, we are going to replace 'the' by substring 'best' using %str:the=best% statement. Explanation : By using ' set ' we are getting input of a
1 min read
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" pauseExplanation :By using ' set ' we are getting our input st
1 min read
Batch Script - Create String
In this article, we are going to learn how to create a String using Batch Script. Batch Script :@echo off set str=Geeks for Geeks echo %str% pauseBy using ' set ' we are getting input of any string.Ex: set str=input stringIn the next line, we are using ' echo %str% ' for printing our input string.Then we are using 'pause' , to hold the screen until
1 min read
Batch Script - Left String
In this article, we are going to study Left string in Batch Script. In Batch Script, the Left string is used to extract the characters from the beginning of the string by giving position 0 and a length using:~ while expanding a variable content. Example 1: Batch script set str=GeeksForGeeks echo.%str% set str=%str:~0,5% echo.%str% Output GeeksForGe
1 min read
Batch Script - String length
In this article , we are going to learn how to find length of any String using Batch Script. Batch Script :@echo off set str=Geeks For Geeks call :strLen str strlen echo String is %strlen% characters long pause exit /b :strLen setlocal enabledelayedexpansion :strLen_Loop if not "!%1:~%len%!"=="" set /A len+=1 & goto :strLen_Loop (endlocal &
2 min read
Batch Script - Mid String
In this article , we are going to learn how to use the concept of Mid String using Batch Script. Using the concept of 'Mid String' we are extracting out a sub string between two indices of any given string. Batch Script :@echo off set str=GeeksforGeeks echo %str% set str=%str:~5,-5% echo %str% pause Using above code we are going to print a substrin
2 min read
Batch Script - Right String
In this article, we are going to learn how to use the concept of Right String using Batch Script. Right String uses the concept of negative indexing. We have to extract the characters using :~ followed by the negative index of the character from which we want to print a substring from the main string. Using the right string we can print characters
2 min read
Batch Script - String Interpolation
String interpolation is a technical way of saying parsing a value that might be a variable into a string. It is an important part of dealing with the application that contains texts in some way to make them dynamic and programmatic. In batch scripting, we can perform string interpolation as well as it is technically a programming language for the c
2 min read
Article Tags :
three90RightbarBannerImg