Forum Discussion

Michael_Koyfma1's avatar
Apr 14, 2006

Concatenate two values into one

I need to ocncatenate two values into one variable and separate them by a :

 

 

Basically, I need to build a string/variable that looks like clientaddress:clientport. I've tried to enter this in the iRule:

 

 

set srctoken [concat [IP::addr] [TCP::client_port]]

 

 

However, when I try to save the iRule, I get an error that says [wrong args] [IP::addr]

 

 

Also, I can't seem to figure out what's the proper way to insert a ":" betweent he argument. If the client's IP address is 10.1.1.1 and destination port is 80, then I need to create a string that looks like 10.1.1.1:80

 

 

Any help is greatly appreciated.

 

 

-Michael

 

3 Replies

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    Oh, as to your second question, you can try just setting the variable, rather than using concat, if you want to add something in between the two values.

    Something like this:

    
    set myVar [IP::client_addr] + ":" + [TCP::client_port]
    or
    set myVar "[IP::client_addr] : [TCP::client_port]"

    HTH,

    Colin
  • i get a syntax error trying to do something like:

     

    set myVar [IP::client_addr] + ":" + [TCP::client_port]

     

     

    wrong number arguments.. i need to do the same.. create a single string without spaces with two constants and a variable

     

     

    if $myhost is abcd

     

     

    "string1" $myHost "string2"

     

     

    so it is string1abcdstring2 would be the result
  • Hi Brad,

     

     

    You can just put commands together in a quoted string:

     

     

    set myVar "[IP::client_addr]:[TCP::client_port]"

     

     

    For variables you can use curly braces to delineate the variable name:

     

     

    set myVar "string1${myHost}string2"

     

     

    Aaron