dynamic variable replacement?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
miskox
Posts: 666
Joined: 28 Jun 2010 03:46

dynamic variable replacement?

#1 Post by miskox » 16 Apr 2012 05:15

Ok, title is probably not what it should be - I will change it if I remember anything else.

I have this problem:

Code: Select all

@echo off
set /a counter=0
set var2=sometextetc
:0
set var1=%var2:~%counter%,1%
set /a counter=counter + 1
echo %var1%
if %counter% leq 10 goto :0
REM above we make sure string length is correct - this is not important here


This does not work. What should be done? I prefer a solutoin without a delayed expansion.

Thanks,
Saso

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: dynamic variable replacement?

#2 Post by foxidrive » 16 Apr 2012 05:42

if you don't have ^ characters in your string:

Code: Select all

call set var1=%%var2:~%counter%,1%%

miskox
Posts: 666
Joined: 28 Jun 2010 03:46

Re: dynamic variable replacement?

#3 Post by miskox » 16 Apr 2012 05:46

@foxidrive: Thank you.

I remember I used it once just couldn't find it/remember where it was. Here it is viewtopic.php?p=3899#p3899

Thanks again,
Saso

Post Reply