set str1=%str:~%%G,9% doesn't work. Why?

December 15, 2010 at 19:55:39
Specs: Windows XP
set str abcde

FOR /L %%G IN (1,1,5) DO set teststr=%str:~%%G%
does not yield teststr as
abcde
bcde
cde
de
e

but
FOR /L %%G IN (1,1,5) DO set teststr=%str:~*%
where * = 1,2,3,4,5 does yield the result
Is there syntax for converting %%G to numeric to make this work?


See More: set str1=%str:~%%G,9% doesnt work. Why?

Report •

#1
December 15, 2010 at 21:05:24
It doesn't work because of a variable expansion issue.

http://www.computing.net/howtos/sho...

set str=abcde

FOR /L %%G IN (0,1,4) DO (
    call set teststr=%%str:~%%G%%
    call echo.%%teststr%%
)

Should work, so will using delayed expansion:

setlocal enabledelayedexpansion
set str=abcde

FOR /L %%G IN (0,1,4) DO (
    set teststr=!str:~%%G!
    echo.!teststr!
)


Report •
Related Solutions


Ask Question