I want to thank all DosTips members for their efforts and all these nice tools !
Here, i discovered how to make recursive functions in Dos ! - Priceless -
I know you already made a StrLen function, but i created my own with a different method.
Before knowing about these recursive functions i used to make an infinite loop with a DEFINED test inside it (to quit the loop) and reduce the string from 1 character by each loop...
Here is my new StrLen recursive function (more elegant than my old infinite loop):
Code: Select all
:StrLen "Str", NbCar
:: StrLen function compute the input string's length from 0 (empty) to DOS limit
:: -- Str [in] - Any string
:: -- NbCar [in,out] - Variable reference (input) and length (input, output)
SETLOCAL
SET "Str=%~1"
SET /A "NbCar=%~2"
IF DEFINED Str (SET /A "NbCar+=1"& CALL %0 "%Str:~1%", NbCar)
(
ENDLOCAL &:: RETURN VALUE
IF "%~2" NEQ "" SET "%~2=%NbCar%"
)
GOTO :EOF
:: End Function StrLen