Forum Discussion

Andrea_Arquint's avatar
Andrea_Arquint
Icon for Nimbostratus rankNimbostratus
Aug 14, 2013

match strings between delimiters

Hi

I do have an irule that contains:

if {$al_ctrl_parameter contains $switch_app_pool }

switch_aap_pool could contain myURI_A1 or myURI
al_ctrl_parameter could contain TEST=myURI_A1,myURI,myURI_A2,myURI_A3& (delimited with commas)

In that case if somebody would use the URI myURI it would match to all al_ctrl_parameter. How can I check with the if statement the strings between the delemiters (commas)?

thanx bb

2 Replies

  • uni's avatar
    uni
    Icon for Altostratus rankAltostratus

    I assume you want different actions depending on which of these strings match. I would use a switchstatement and put the myURI test after all the ones which also contain that string:

    switch -glob -- $al_ctrl_parameter {
      "*myURI_A1*" { do stuff }
      "*myURI_A2*" { do stuff }
      "*myURI_A3*" { do stuff }
      "*myURI*"    { do stuff }
    } 
    

    It is kind of inefficient though. If the test string is the whole $al_ctrl_parameter, you can remove the -glob and asterisks, and then it would not be dependent on the order.

  • uni's solution would work assuming that the literals you have specified are as specified.

    Couldn't you just enclose your contains string with commas?

    if {$al_ctrl_parameter contains ",$switch_app_pool," }

    But, that would assume that all the items in al_ctrl_parameter be delimited on both sides by commas but that doesn't look like it's the case in your example. If you can't rely on that, I'd do something with one or maybe two split statements to first break the string and extract the "myURI_A1,myURI,myURI_A2,myURI_A3" and then do another split with a comma being a delimiter. Then you can iterate through that list to see if you find a match.

    Let us know if the first solution works of if you need help implementing another option.

    -Joe