locked
Adding brackets to variable RRS feed

  • Question

  • Hi,

    Stupid question but didn't find answer yet: how can I add brackets to my variable,

    $VariableWithoutBrackets = "1.0"
    $VariableWithBrackets = '('$VariableWithoutBrackets')'

    So that $VariableWithoutBrackets  = 1.0 and $VariableWithBrackets = (1.0)

    ?

    Please advise.
    J.


    Jan Hoedt

    Monday, September 14, 2015 10:29 AM

Answers

  • $VariableWithBrackets ="($VariableWithoutBrackets)"

    OR

    $VariableWithBrackets ='('+$VariableWithoutBrackets+')'

    ...and those are parenthesis ;)


    Please remember to: "Vote" if my response was helpful. "Mark As Answered" if I answered your question correctly. V/R, Darrick West - Senior Systems Engineer, ConfigMgr: OSD



    • Proposed as answer by Darrick West Monday, September 14, 2015 12:22 PM
    • Edited by Darrick West Monday, September 14, 2015 12:26 PM
    • Marked as answer by janhoedt Tuesday, September 15, 2015 9:32 AM
    Monday, September 14, 2015 12:22 PM

All replies

  • Clarification - what do you mean by "brackets"? You've posted an example with parentheses.


    Monday, September 14, 2015 12:01 PM
  • $VariableWithBrackets ="($VariableWithoutBrackets)"

    OR

    $VariableWithBrackets ='('+$VariableWithoutBrackets+')'

    ...and those are parenthesis ;)


    Please remember to: "Vote" if my response was helpful. "Mark As Answered" if I answered your question correctly. V/R, Darrick West - Senior Systems Engineer, ConfigMgr: OSD



    • Proposed as answer by Darrick West Monday, September 14, 2015 12:22 PM
    • Edited by Darrick West Monday, September 14, 2015 12:26 PM
    • Marked as answer by janhoedt Tuesday, September 15, 2015 9:32 AM
    Monday, September 14, 2015 12:22 PM
  • Try:

    $var2 = "("+$var1+")"

    wizend

    Monday, September 14, 2015 12:33 PM
  • Your method will work - with ' as well - but there is a more efficient way of doing this.

    Removing the + operators and the inside " will expand the variable and create the new string.

    $var2 = "($var1)"


    Please remember to: "Vote" if my response was helpful. "Mark As Answered" if I answered your question correctly. V/R, Darrick West - Senior Systems Engineer, ConfigMgr: OSD


    Monday, September 14, 2015 12:54 PM

  • $var2 = "($var1)"


     


    A more general pattern would be
    $var2 = "($($var1))"
    Suppose instead of parenthesis you wanted to wrap the value with underscores.
    $var2 = "_$var1_"      # does not work
    $var2 = "_$($var1)_"   # works
    
    



    Monday, September 14, 2015 2:32 PM
  • Yep.

    Add the $() sub-expression operator to the list of working suggestions.


    Please remember to: "Vote" if my response was helpful. "Mark As Answered" if I answered your question correctly. V/R, Darrick West - Senior Systems Engineer, ConfigMgr: OSD

    Monday, September 14, 2015 4:20 PM