Open In App

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 substring from 5 to -5 index from given string(i.e. GeeksforGeeks).

Explanation :

set str=GeeksforGeeks
set str=%str:~5,-5% 



As we can clearly see that characters between ‘5’ and ‘-5’ is printed as output ,so using the following code we can use the concept of Mid String.

Article Tags :