Layer 7 API Management

Expand all | Collapse all

cast string to integer

Jump to Best Answer
  • 1.  cast string to integer

    Posted 04-14-2017 06:11 AM

    how can I trasform a string to an integer value?



  • 2.  Re: cast string to integer
    Best Answer

    Posted 04-14-2017 11:45 AM

    Giovanni,

    Not sure if this helps, set an Integer variable to the value of a String variable. 



  • 3.  Re: cast string to integer

    Posted 04-18-2017 04:40 AM

    Hi,

     

    I tried your solution, but i can't set to integer a string.



  • 4.  Re: cast string to integer

    Posted 04-18-2017 11:40 PM

    Hi, 

     

    Even I have same query. Can anyone please help in this.

     

    Thanks,

    Ravish



  • 5.  Re: cast string to integer

    Posted 04-19-2017 12:17 AM

    If the value of the string is 'integer', then that string value can be defined as Integer. But if the value of the string is not integer, then 'Unable to parse Integer string' will be encountered and this is expected behaviour.  So, String value cannot be transformed as Integer.



  • 6.  Re: cast string to integer

    Posted 04-19-2017 12:24 AM

    I have set a context variable "cv_Integer" as data type "Integer" with value: 0. Now, I want to increment this value. So, I tried to keep same context variable "cv_Integer" as data type "Integer" with value: ${cv_Integer} + 1".

    Now, I am getting the error "Unable to parse Integer String:"



  • 7.  Re: cast string to integer

    Posted 04-27-2017 09:23 PM
      |   view attached

    Hi,

    I believe the expression in context variable is always treated as a string.

    ie. in your example, it will try to cast "0 + 1" to integer, it won't calculate it first.

     

    Except the tactical assertion mentioned by Provida Burusu, you can also use xpath to do some simple calculation.

     

     

    sample policy attached.



  • 8.  Re: cast string to integer

    Posted 04-19-2017 04:36 AM

    There is a Tactical assertion named 'Evaluate Math Expression assertion' to perform these operations. You can download this fromMath Expression Assertion.