Answered

Get a substring of string after a particular character

I have a string that I am reading through GET_WEB_VALUE as shown below:

string = "Date: 11‑30‑2021, Complete, Due: 12‑10‑2021, $500.00, Unpaid: 3, $500.00"

I want to get only the '500.00' right at the end, ignoring everything else before that and store it in a variable. How can I achieve that?

0
4 comments
Avatar
Raunak Nandy (US - ADVS)

In my scenario, the string is dynamic, for eg:

String 1 : "Date: 11‑30‑2021, Complete, Due: 12‑10‑2021, $500.00, Unpaid: 3, $500.00"

String 2 : "Date: 11‑30‑2021, Pending, Due: 12‑10‑2021, $23, Unpaid: 1, $1,765"

In string 2, I would just like the 'Unpaid' amount, i.e. 1765.

 

 

0
Comment actions Permalink
Avatar
Raunak Nandy (US - ADVS)

If I used the Sub_string command, the index would keep on changing as the string is dynamic. One thing that remains constant is that I need to get only the 'Unpaid' amount (mentioned right at the end).

One solution that I have tried is to use the Execute_Javascript with the following piece of code:

string = Date: 11‑30‑2021, Complete, Due: 12‑10‑2021, $500.00, Unpaid: 3, $500.00

string.substring(string.lastIndexOf('$') + 1)

Although this code works fine, I am unable to figure out how to pass the variable 'string' onto the Execute_Javascript command, its being fetched from the UI in the previous step using Get_Web_Value with variable 'string'. 

0
Comment actions Permalink
Avatar
Joseph Hamdan

Hi Raunak,

We're glad you figured out the right code. You can basically use the same variable from your Get_Web_Value command that retrieves the whole line and add it as string value in another Get_Web_Value step with Javascript Source Type.

string = "@string"

return string.substring(string.lastIndexOf('$') + 1)

Example:

Please let us know if you require any additional help.

Regards,
Subject7 Team

0
Comment actions Permalink

Please sign in to leave a comment.