Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
[newbie]
- Posts: 6
- Joined: 07 Feb 2015 15:02
#1
Post
by [newbie] » 04 Sep 2015 06:52
Hi
I would like to add a
wow_ to the old variable
set "oldV=aaa bbb ccc ddd"and the finished variable should look like
set "newV=
wow_aaa wow_bbb wow_ccc wow_ddd"
I get it only to:
Code: Select all
@echo off
Setlocal EnableDelayedExpansion
set "addV=wow_"
set "oldV=aaa bbb ccc ddd"
for %%i in (%oldV%) do (
set "newV=!addV!%%i"
echo !newV!
REM to new assemble...
)
How can i get the new variable composited?
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#2
Post
by foxidrive » 04 Sep 2015 07:04
Here is one way:
Code: Select all
@echo off
set "addV=wow_"
set "oldV=aaa bbb ccc ddd"
for %%a in (%oldV%) do call set "newv=%%newv%% %addV%%%a"
set "newv=%newv:~1%"
echo %newV%
pause
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#3
Post
by Squashman » 04 Sep 2015 07:05
Code: Select all
@echo off
Setlocal EnableDelayedExpansion
set "addV=wow_"
set "oldV=aaa bbb ccc ddd"
for %%i in (%oldV%) do (
set "newV=!newV!!addV!%%i "
echo !newV!
REM to new assemble...
)
-
Yury
- Posts: 115
- Joined: 28 Dec 2013 07:54
#5
Post
by Yury » 04 Sep 2015 09:06
Code: Select all
@echo off
setlocal enabledelayedexpansion
set "oldV=aaa bbb ccc ddd"
set "addV=wow_"
set "newV=%addV%!oldV: = %addV%!"
echo %newV%
-
[newbie]
- Posts: 6
- Joined: 07 Feb 2015 15:02
#6
Post
by [newbie] » 06 Sep 2015 09:44
Yury wrote:Code: Select all
@echo off
setlocal enabledelayedexpansion
set "oldV=aaa bbb ccc ddd"
set "addV=wow_"
set "newV=%addV%!oldV: = %addV%!"
echo %newV%
Thx, very nice implementation.