Input string was not in a correct format -Get text activity

Hi all,

I’m trying to get text from the website and use the page number as a counter in the loop. And the error ‘Input string was not in a correct format’ would sometimes occurs which I’m confused cause it does not occur every time I run the workflow. Here is what I did:

Activity1: Assign page=“” (datatype: string)
Activity2: Get text save to page
Activity3: Assign grant= System.Text.RegularExpressions.Regex.Match(page,”\d+(?=page)”).Value.replace(" “,”") (datatype: string)
Activity4: Assign total= integer.parse(grant) (datatype: Int32)

And the error would sometime occur on activity 4, do you have any idea about how to deal with this issue, thanks a lot!

Hi @Paddi

The error occurs in Activity 4 because the grant variable might not always contain a valid integer value. This issue can arise if the regular expression pattern doesn’t match any digits or if there are leading or trailing whitespaces in the extracted value.

Try this to tackle the issue:

For Activity 3 →

Assign grant = System.Text.RegularExpressions.Regex.Match(page, "\d+(?=page)").Value.Trim()

Before proceeding with the Activity 4, use an If condition to check the RegEx outcome:

Not String.IsNullOrEmpty(grant)

If this holds true, For Activity 4 →

Assign total = Integer.Parse(grant)

Hope this helps,
Best Regards.

1 Like

Hi @arjunshenoy, thanks for your solution, and I’m wondering if I need to write anything for the [Else] in this If activity?

Hi @Paddi

In the else part, you can implement the exception handling sequence. Either you can throw an error saying that the RegEx output in not valid for further operation & thus notify the process owner or you can just keep the Else part empty. This entirely depends on your requirements & use case.

Hope this helps,
Best Regards.

Thanks again!

Hi @arjunshenoy, What if I want to ensure that the get text activity can get the page number as a counter for the loop? Cause the get text activity is necessary for the next steps.


You can do that, as long as you are iterating through the pages in a sequential manner.

Best Regards.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.