Batch Script - Replace a String Last Updated : 28 Nov, 2021 Comments Improve Suggest changes Like Article Like Report 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 any stringset str=input stringIn the next line using ' echo %str% ' we are printing our string.Using ' %str:the=best%' statement , we are replacing substring 'the' with 'best'.Then using 'pause', to hold the screen until any key is pressed, so that we can read our output. Output : 'the' is replaced by 'best'Another Approach :Batch Script :@echo off set str=GFG is the platform for geeks. set word=best echo %str% call set str=%%str:the=%word%%% echo %str% pause Explanation : Everything is as same as before, we are trying to replace the word 'the' with 'best' but we can also do this by calling another variable 'word' which is equal to 'best'.By using call there is another layer of variable expansion so we have to use '%' for 'word' so that it will use 'best' as its value and replace the string.output by 2nd approach Comment More infoAdvertise with us Next Article Batch Script - Replace a String thenavneet Follow Improve Article Tags : Linux-Unix Batch-script Similar Reads 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.Th 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.%st 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" pauseExplana 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 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 strin 2 min read Batch Script - Strings A Bash script is a plain text file. This file contains different commands for step-by-step execution. These commands can be written directly into the command line but from a re-usability perceptive it is useful to store all of the inter-related commands for a specific task in a single file. We can u 4 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 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 2 min read Batch Script - String Concatenation 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 stri 2 min read Batch Script - Remove All Spaces In this article, we are going to see how to remove all spaces from any string using Batch String. Example : Input: G e e k s f o r G e e k s Output: GeeksforGeeksApproach :By using ' set ' we are getting input of any string.Example: set str=input stringIn the next line using ' echo %str% ' we are pr 1 min read Like