0

So, let's say I have a value call value it's value is hello goodbye

Let's say I have another value called value2 it's value is there

 set value=hello goodbye

 set value2=there

Is there anyway to put value2 into value, so that if echo'd it'd be printed out as hello there goodbye.

2
  • Batch? What is batch? You don't know name of the language? Commented Nov 22, 2013 at 18:52
  • 2
    Windows Command Shell Script Language (WCSSL) aka Batch. Commented Nov 22, 2013 at 18:59

2 Answers 2

3

Lots of ways:

To insert the string at a particular position:

set value=hello goodbye
set value2=there
set "value=%value:~0,5% %value2%%value:~6%"

To substitute the string for every space within the first variable:

setlocal enableDelayedExpansion
set value=hello goodbye
set value2=there
set "value=!value: = %value2% !"

To break the string at the first space (or set of spaces), and insert the string:

set value=hello goodbye
set value2=there
for /f "tokens=1*" %%A in ("%value%") do set "value=%%A %value2% %%B"
Sign up to request clarification or add additional context in comments.

1 Comment

So we meet again, thanks for explaining how too place it in other places, whilst I did not ask I was wondering about that. Thanks once again.
2

Like this:

@echo off
setlocal enabledelayedexpansion

set value=hello goodbye
set value2=there

set value=!value: = %value2% !

echo %value%

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.