Recently I needed to determine the length of a string and perform a Substring operation on a variable in a DOS Batch (.bat) file. (Yes, people still use DOS batch files!)
After some Googling and some playing around I came up with the following functions.
:: extracts the substring from string starting at startIndex for the specified length
if "%4" == "0" goto :noLength
CALL SET _substring=%%string:~%startIndex%,%length%%%
CALL SET _substring=%%string:~%startIndex%%%
::returns the length of the string specified in %2 and stores it in %1
if defined # (set #=%#:~1%&set /A length += 1&goto stringLengthLoop)
::echo the string is %length% characters long!
To call them:
:: get the lenth of the sConfigFileRoot
call:StrLength length %sCFR%
:: extract the suffix