Right String with variable index

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mowmow
Posts: 4
Joined: 02 Nov 2009 18:43

Right String with variable index

#1 Post by mowmow » 02 Nov 2009 18:54

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

mowmow
Posts: 4
Joined: 02 Nov 2009 18:43

#2 Post by mowmow » 02 Nov 2009 19:44

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

isacmahad
Posts: 44
Joined: 29 Oct 2009 23:08

#3 Post by isacmahad » 02 Nov 2009 23:59

Yes take a look at my post.
I am working on this.

Post Reply