LHRH
LHRH

Reputation: 13

How do I combine a variable and a text string in batch?

@echo off
set /a hlo=Hello
:start
echo %hlo%
pause
set /a hlo=%hlo% + World
goto start
pause

I want to make hlo become "HelloWorld".

Upvotes: 0

Views: 97

Answers (1)

phuclv
phuclv

Reputation: 42032

Just remove /a

set "hlo=Hello"
set "hlo=%hlo% World"

Because set /a is for doing arithmetics and not for string operations

set /?
...
Two new switches have been added to the SET command:

    SET /A expression
    SET /P variable=[promptString]

The /A switch specifies that the string to the right of the equal sign
is a numerical expression that is evaluated.  The expression evaluator
is pretty simple and supports the following operations, in decreasing
order of precedence:
...

Upvotes: 1

Related Questions