how concatenate two variables in batch script?

前端 未结 3 1394
野的像风
野的像风 2021-02-02 15:54

I want to do something like this in batch script. Please let me know if this is the proper or possible way to do it or any other way?

set var1=A

set var2=B

set         


        
3条回答
  •  天命终不由人
    2021-02-02 16:34

    The way is correct, but can be improved a bit with the extended set-syntax.

    set "var=xyz"
    

    Sets the var to the content until the last quotation mark, this ensures that no "hidden" spaces are appended.

    Your code would look like

    set "var1=A"
    set "var2=B"
    set "AB=hi"
    set "newvar=%var1%%var2%"
    echo %newvar% is the concat of var1 and var2
    echo !%newvar%! is the indirect content of newvar
    

提交回复
热议问题