Page 1 of 1

Right String with variable index

Posted: 02 Nov 2009 18:54
by mowmow
Hi Everyone,

In the snippet below, "-4" serves as the index for the Right String function provided on this site. Is there a way to replace this constant with a variable such as "indx", the value of which may be -4? Simply replacing "-4" with "%indx%" does not work, and my search for a solution has not been fruitful.

SCRIPT:
set str=politic
echo.%str%
set str=%str:~-4%
echo.%str%

OUTPUT:
politic
itic

Thanks,
Andy

Posted: 02 Nov 2009 19:44
by mowmow
OK. The adjacent post has the answer:

set indx=-4
set str=politic
echo.%str%
call set "str=%%str:~%indx%%%" <<===== The Key!
echo.%str%

Andy

Posted: 02 Nov 2009 23:59
by isacmahad
Yes take a look at my post.
I am working on this.