07-23-2023, 09:42 AM
This works too. Also its simple and easy to understand.
setlocal
set strcopy=thisismystring
set count=0
:testremovecount
if "%strcopy%"=="" goto done
set strcopy=%strcopy:~1%
set count=%count%+1
goto testremovecount
:done
endlocal
set "strcopy" to your string
output is "count"
The most complicated part is
set strcopy=%strcopy:~1%
The "%strcopy:~1%" part if this line removes only the first character from the string variable "strcopy". for more info see
setlocal
set strcopy=thisismystring
set count=0
:testremovecount
if "%strcopy%"=="" goto done
set strcopy=%strcopy:~1%
set count=%count%+1
goto testremovecount
:done
endlocal
set "strcopy" to your string
output is "count"
The most complicated part is
set strcopy=%strcopy:~1%
The "%strcopy:~1%" part if this line removes only the first character from the string variable "strcopy". for more info see
[To see links please register here]