Test string before converting to string to integer

1
I want to convert a string to an integer (parseInteger). But in my application I cannot be sure that the string is an integer. Is there a way to test the string if it is an integer, before I convert it?
asked
3 answers
5

Why not use the default value with the parseinteger function? If you set this then the integer gets this value when the parseinteger fails. You can then check if the parseinteger has this value and do something.

Regards,

Ronald

answered
3

Yes, you could do that by adding error handling to your parseInteger activity. If your action fails, you can handle it without an exception. Sometimes I create a microflow which is testing all my expressions and only continue to the real convert when this one works.

Handling exception

answered
2

Use regular expressions. Implement a split with condition: isMatch($yourIntString, '^([0-9]+)$'). When true you can use the parseInteger function.

Imo this is better than try and catch exceptions.

answered