如何批量合并变量和文本字符串?

时间:2018-07-01 17:01:49

标签: batch-file environment-variables

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

我想使“ hlo”成为“ HelloWorld”。

1 个答案:

答案 0 :(得分:1)

只需删除/a

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

因为set /a用于算术,而不用于字符串运算

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:
...