I wanted to create my own "stringLength" script and I managed to do it but I do not understand one line of code that I borrowed from https://ss64.com/nt/syntax-substring.html ( check near the bottom of the page )
My script is:
@echo off
::initializing variables
SET strlen=0
SET "string=stringToBeMeasured"
:: adding } at the end of the string to signal the end of the count
set "string=%string%}"
:main
call SET chosenchar=%%string:~%strlen%,1%%
:: if the character is not } then add string lenght +1 until...
if "%chosenchar%" neq "}" (
set /a strlen=%strlen%+1
goto :main
)
:: when you see the designated } character, then print the result and exit
if "%chosenchar%" == "}" ( goto :exit )
:exit
echo Your string length is: %strlen%
pause
And the line I do not understand how exactly works is:
call SET chosenchar=%%string:~%strlen%,1%%
Why do I have to CALL it and not just SET it? Can you guide me with a lot of details?
Thanks in advance!