Forum Discussion

Barry_Gavenda's avatar
Barry_Gavenda
Icon for Nimbostratus rankNimbostratus
Jun 24, 2019

Variable in a string map

We are using a string map where we are replacing the value found with a variable. Sounds nice, but we can't get it to work. F5 just sends it the $variable (literally). Tried brackets, quotes, everything. Ideas on how to do this?

 

set variable = "xxxx"

    set newpoolname [string map -nocase {"-app" $variable} $defaultpool]

result is -app is replaced with $variable (not xxx).

2 Replies

  • String map expect a list as argument...

     

    you can create a list with following format:

     

     

    >set variable = "xxxx"
    # curly brackets doesn’t support variables
    set newpoolname [string map -nocase {"-app" $variable} $defaultpool]
    # list command between brackets with even parameter numbers is the best solution
    set newpoolname [string map -nocase [list "-app" $variable] $defaultpool]
    # create a string with space... it will be converted to a list with space as separator (less efficient than list and curly brackets)
    set newpoolname [string map -nocase "-app $variable" $defaultpool]