Code: Select all
:test2
echo on
setlocal EnableDelayedExpansion
set "input_line=1234567"
set "count_of_chars=2"
echo %input_line:~0,!count_of_chars!%
endlocal
goto :eof
Thanks
Moderator: DosItHelp
Code: Select all
:test2
echo on
setlocal EnableDelayedExpansion
set "input_line=1234567"
set "count_of_chars=2"
echo %input_line:~0,!count_of_chars!%
endlocal
goto :eof
Code: Select all
echo !input_line:~0,%count_of_chars%!
Code: Select all
:test4
echo on
setlocal EnableDelayedExpansion
set "input_line=1234567"
set "n=1"
for /l %%i in (1,1,7) do (
set "count_of_chars=!n!"
echo !input_line:~0,%count_of_chars%!
set /a "n=n+1"
)
endlocal
goto :eof
You need to expand !count_of_chars! inside ( )sincos2007 wrote: ↑11 Apr 2019 22:30hi Steffen,
I have test the code you post, it really works. Thanks.
There is another code related to this topic which not work:
This code have a for loop, which not work by your code.Code: Select all
:test4 echo on setlocal EnableDelayedExpansion set "input_line=1234567" set "n=1" for /l %%i in (1,1,7) do ( set "count_of_chars=!n!" echo !input_line:~0,%count_of_chars%! set /a "n=n+1" ) endlocal goto :eof
Thanks.
Code: Select all
for /l %%i in (1,1,7) do echo !input_line:~0,%%i!
Code: Select all
for /l %%i in (1,1,7) do (
for %%j in (!n!) do echo !input_line:~0,%%j!
set /a "n+=1"
)
sincos2007 wrote: ↑12 Apr 2019 04:02Hi IcarusLives,
Could you show me how to expand !count_of_chars! inside ()?
Thanks
Code: Select all
call echo %%input_line:~0,!count_of_chars!%%
or
for %%i in (!count_of_chars!) do echo !input_line:~0,%%i!