DataDesignIT
asked on
How to dynamically create variables with string trim
Experts-
I currently have a list of items. For each, I want to dynamically create variables for each, and use just the suffix (trim off the \\blade prefix).
SET SLIST=\\blade3c \\blade3d \\blade3f
FOR %%s IN (%SLIST%) DO [...]
I want to trim the string so I get three new variables, the same as if I did the following:
SET 3c=\\blade3c
SET 3d=\\blade3d
SET 3f=\\blade3f
How do I accomplish this?
Thanks.
I currently have a list of items. For each, I want to dynamically create variables for each, and use just the suffix (trim off the \\blade prefix).
SET SLIST=\\blade3c \\blade3d \\blade3f
FOR %%s IN (%SLIST%) DO [...]
I want to trim the string so I get three new variables, the same as if I did the following:
SET 3c=\\blade3c
SET 3d=\\blade3d
SET 3f=\\blade3f
How do I accomplish this?
Thanks.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Good luck on your future questions...
@echo off
setlocal
set sList=\\blade3c \\blade3d \\blade3f
for /f "tokens=*" %%a in ('echo %sList%') do call :PROCESS %%a
echo 3c %_3c%
echo 3d %_3d%
echo 3f %_3f%
goto :EOF
:PROCESS
if "%~1"=="" goto :EOF
set _t=%~1
set _t=%_t:~-2%
set _%_t%=%~1
shift
goto PROCESS
Good Luck,
Steve