Forum Discussion
testing for empty string
I am very new to iRules. Two quesitons:
1.) Is there a function to test if a string variable is the empty string? In my particular case, I am using regexp to populate a string variable and later in the irule, I want to know if the string was populated or not.
2.) How do you define an integer variable? I want to capture the output of the regexp call and store it in an integer variable and later I can test if that variable equals 0 or 1.
Thanks
1.) Is there a function to test if a string variable is the empty string? In my particular case, I am using regexp to populate a string variable and later in the irule, I want to know if the string was populated or not.
set val [HTTP::header "foo"] if { [string length $val] == 0 } { log local0. "foo header didn't exist" }
2.) How do you define an integer variable? I want to capture the output of the regexp call and store it in an integer variable and later I can test if that variable equals 0 or 1.
- vm_64966
Nimbostratus
Thanks for your help. - That's hard to answer exactly without something to test against and there is a lot to take into account with multiple string commands such as the overhead if you are doing temp string allocations. In general though, if you can do it with a handful of string commands, that's preferable.
- Nicolas_Menant_Historic F5 AccountJust some additional stuff, if you want to see how using regexp or string commands impact your performance you have a specific command you can use to evaluate this:
- lbertacco
Nimbostratus
1) I'd go with just if { $var eq "" } or if { $var ne "" } for the opposite condition.
- Nicolas_Menant
Employee
Just some additional stuff, if you want to see how using regexp or string commands impact your performance you have a specific command you can use to evaluate this:- lbertacco
Nimbostratus
1) I'd go with just if { $var eq "" } or if { $var ne "" } for the opposite condition.
Recent Discussions
Related Content
* 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