Jump to content

Recommended Posts

Posted

Hello,

I have the following batch file:

SET %one% = "test"

SET %two% = "program"

Now I want %three% to contain somethign like this:

SomeWordstestprogram

That means that I want to have a string, attach %one% and then %two% to it and then write it into %three%.

How is that possible?

I tried PHP syntax but that didn't work ;)


Posted

Hello,

This worked:

SET three = "SomeWord" + %one% + %two%

However, when I want to see whats in %three%, I don't get anything.

echo %three%

gives me

"echo is turned ON"

or something like that (it's a German Windows, so I had to translate it).

What am I doing wrong?

Posted

i found THIS for you

i never worked with batch commands but looking at some examples, i think you should try like this:

SET one = string1

SET two = string2

SET three = "some other string " + one + " " + two

ECHO %three%

Posted (edited)

You've got the wrong syntax for SET.

The correct syntax is: SET variable=string

SET one=test
SET two=program
SET three=SomeWord%one%%two%

echo %one%
echo %two%
echo %three%

Edited by [deXter]
Posted (edited)

set three = someword%one%%two%

echo %three%

leave no spaces and exclude "+" between %one% and %two%.

Edit: dexter beat me to it.

Edited by spacesurfer
Posted

Thanks for the link, this finally worked:

SET THREE = SomeWords%one%%two%

SET THREE

The second line is used instead of the echo command.

Posted

Good practice notes:

  • Set your variables local to the running batch session
  • To prevent the inclusion of unwanted whitespace in your variables, enclose them in parentheses (lines 3, 4, 5)

@Echo Off
Setlocal
(Set one=test)
(Set two=program)
(Set three=SomeWords%one%%two%)
Echo/%%three%%=%three%

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...