Open In App

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 & set %2=%len%)
goto :eof

In Batch Scripting there no function for checking length of string ,So we will create a function to find length of string.



Explanation :

if not "!%1:~%len%!"=="" set /A len+=1 & goto :strLen_Loop

Output:



Article Tags :