For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

SysTopher's avatar
SysTopher
Icon for Nimbostratus rankNimbostratus
Sep 28, 2016

Removing a character from a variable using TCL

Hello,

 

iRule newbie here. I'm curious if anyone can give me an idea of how I could take a variable and strip out specific characters. For example, I have an iRule where I'm pulling a variable, such as [ACCESS::session data get "session.custom.variable"] and I want to remove an @ sign if it exists in this variable.

 

Perhaps I could even grab this variable and create a new variable? It's being used in an APM policy, so I would be find doing a variable assign where I get this variable, manipulate it to remove any @ symbol and place it into a new variable and then call this new variable in my iRule.

 

Any tips that any TCL experts can assist me with?

 

Thank you

 

8 Replies

  • set variable [ACCESS::session data get "session.custom.variable"]
    set newVariable [string trim $variable "@"]
    

    Keep in mind this will remove all @ from $variable, regardless of location in the string.

    • ekaleido's avatar
      ekaleido
      Icon for Cirrus rankCirrus

      Or I suppose you could just

      set variable [string trim [ACCESS::session data get "session.custom.variable"] "@"]
      
    • SysTopher's avatar
      SysTopher
      Icon for Nimbostratus rankNimbostratus

      Ekalieido,

       

      This looks like it would work great, but it turns out the APM option that Kai suggested works better with my existing variable assign so I marked his response as the acceptable answer for my case. Unfortunately I can't mark both of you as correct, but for anyone else reading this looking for a similar solution please keep in mind that both of these answers are great suggestions.

       

    • ekaleido's avatar
      ekaleido
      Icon for Cirrus rankCirrus

      No worries! Just glad you were able to get it done.

       

  • set variable [ACCESS::session data get "session.custom.variable"]
    set newVariable [string trim $variable "@"]
    

    Keep in mind this will remove all @ from $variable, regardless of location in the string.

    • ekaleido_26616's avatar
      ekaleido_26616
      Icon for Cirrocumulus rankCirrocumulus

      Or I suppose you could just

      set variable [string trim [ACCESS::session data get "session.custom.variable"] "@"]
      
    • SysTopher's avatar
      SysTopher
      Icon for Nimbostratus rankNimbostratus

      Ekalieido,

       

      This looks like it would work great, but it turns out the APM option that Kai suggested works better with my existing variable assign so I marked his response as the acceptable answer for my case. Unfortunately I can't mark both of you as correct, but for anyone else reading this looking for a similar solution please keep in mind that both of these answers are great suggestions.