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!
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:
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.
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.