Solved variable in a variable

October 9, 2011 at 16:25:58
Specs: Windows XP
This is what I am trying to do:
set %x%1=%s1:~%v%,3%
which is:
set t1=%s1:~0,3%

The problem is that it thinks %s1:~% and %,3% are variables with a v between them.
I have tried many different things but I can't get it to work.
Any ideas?


See More: variable in a variable

Report •

✔ Best Answer
October 10, 2011 at 02:52:57
Now that s1 is set::

@echo off
cls
setlocal enabledelayedexpansion

set s1=123456789
set x=t
set v=0


call set %x%1=%%s1:~!v!,3%%

echo !%x%1!


Please come back & tell us if your problem is resolved.



#1
October 9, 2011 at 18:50:30
Try this, values for X and T are set for testing only.

@echo off
cls
setlocal  enabledelayedexpansion

set x=t
set v=0


call set %x%1=%%%%s1:~!v!,3%%%%

echo !%x%1!


Please come back & tell us if your problem is resolved.


Report •

#2
October 9, 2011 at 20:44:29
Not quite. That literally echos %s1:~0,3%
And I tried changing the number of % and a few other things, but nothing worked. Thanks for trying though.
Oh, and this is what I put:

@echo off
cls
setlocal enabledelayedexpansion

set s1=123456789
set x=t
set v=0


call set %x%1=%%%%s1:~!v!,3%%%%

echo !%x%1!
pause

I might have done something wrong though.


Report •

#3
October 10, 2011 at 00:31:39
http://www.computing.net/howtos/sho...

@echo off
cls
setlocal enabledelayedexpansion

set s1=123456789
set v=0


call echo %%%s1:~!v!,3%%%
echo !s1:~%v%,3!

pause


Report •

Related Solutions

#4
October 10, 2011 at 02:52:57
✔ Best Answer
Now that s1 is set::

@echo off
cls
setlocal enabledelayedexpansion

set s1=123456789
set x=t
set v=0


call set %x%1=%%s1:~!v!,3%%

echo !%x%1!


Please come back & tell us if your problem is resolved.


Report •

#5
October 10, 2011 at 13:04:19
Yes, that works, and returns 123. Thank you! I had thought I tried that, guess not.

Report •

Ask Question