Forum Discussion
Deon
Nimbostratus
Jan 06, 2009How To Concatenate Strings
OK, Newbie here. Trying to figure out how to concatenate strings properly in an iRule. Ive got the following code and the newaddr value is not being formatted like I expect.
...
hoolio
Cirrostratus
Jan 06, 2009Hi Deon,
concat (Click here) will "join each of its arguments together with spaces after trimming leading and trailing white-space from each of them.". You can just combine variables though:
set combined "$var1$var2"
Instead of using getfield twice, you could use scan once:
when RULE_INIT {
set addr [IP::server_addr]
set addr "111.222.333.444"
log local0. "Original \$addr: $addr"
Scan the address for four digits separated by periods
scan $addr {%d.%d.%d.%d} a b c d
Take the third and fourth octets and combine them with the static first two octets.
set newaddr "1.1.$c.$d"
log local0. "scan result: $newaddr"
}
Log output:
Rule : Original $addr: 111.222.333.444
Rule : scan result: 1.1.333.444
Aaron
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects