Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
pumi
- Posts: 15
- Joined: 05 Oct 2013 06:48
- Location: Germany, BW
#1
Post
by pumi » 07 Oct 2013 04:46
Hello,
I try insert a variable into an another variable
I tried this:
Code: Select all
@echo off
set fullstr=asdfghjkl
set /a offset=3
set /a chcount=5
rem set substr=%fullstr:~3,5%
set substr=%fullstr:~%offset%,%chcount%% <- this does't work :-(
echo %substr%
How can I insert the variable into an another variable?
Any idea?
thanks in advance, pumi
-
dwngrt
- Posts: 26
- Joined: 07 Oct 2013 05:14
- Location: The Netherlands
#2
Post
by dwngrt » 07 Oct 2013 05:24
Hello, i am not sure and didn't tested this but i think it should work this way:
set substr=%fullstr:~%%offset%,%chcount%
-
jeb
- Expert
- Posts: 1062
- Joined: 30 Aug 2007 08:05
- Location: Germany, Bochum
#3
Post
by jeb » 07 Oct 2013 05:36
You need two expansion phases here.
First for the numbers and then for the main variable expansion.
There are multiple ways to solve it, here is one
Code: Select all
setlocal enableDelayedExpansion
set /a offset=3
set /a chcount=5
rem set substr=%fullstr:~3,5%
set substr=!fullstr:~%offset%,%chcount%!
-
pumi
- Posts: 15
- Joined: 05 Oct 2013 06:48
- Location: Germany, BW
#4
Post
by pumi » 07 Oct 2013 07:04
thanks for your help, it works!