【问题标题】:How do I combine a variable and a text string in batch?如何批量组合变量和文本字符串?
【发布时间】:2018-07-01 17:01:48
【问题描述】:
@echo off
set /a hlo=Hello
:start
echo %hlo%
pause
set /a hlo=%hlo% + World
goto start
pause

我想让hlo 变成“HelloWorld”。

【问题讨论】:

    标签: batch-file environment-variables


    【解决方案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:
    ...
    

    【讨论】:

    • 非常感谢! (一个漂亮的菜鸟问题,但很难记住所有这些);)
    猜你喜欢
    • 2015-07-29
    • 1970-01-01
    • 2017-06-29
    • 1970-01-01
    • 2016-05-07
    • 2015-03-31
    • 2011-06-25
    • 1970-01-01
    • 2019-05-15
    相关资源
    最近更新 更多