String Index OutOfBounds Exception

0
Is there a limitation to a String variable within a microflow? During the creation of the variable (which I use for email content) I get an Error stating "StringIndexOutOfBoundsException: String index out of range: 150" Failed to evaluate expression, error occurred on line 5, character 111 if ($Message/Content != empty and $Message/Content != '') then ''+substring($Message/Content,0,(find($Message/Content,':')+1))+''+substring($Message/Content,(find($Message/Content,':')+2),(find($Message/Content,'Please')))+''+substring($Message/Content,(find($Message/Content,'Please')-1))+'' else '' Anyone knows what this is? I believe the expression to be correct.
asked
3 answers
3

You are not ensuring that the indices are within the bounds of your string. For example, find($Message/Content,':')+2. You do not know if the index at which ':' is found +2 is a valid index in your string. If the colon is at 148, and your string is only 149 characters then 150 will result in an out of bounds exception.

To more easily debug and see what I mean, you should put each of your expressions into variables. Put each find expression into its own integer variable. Then you can verify if the indices are within bounds.

EDIT: It seems you are essentially re-piecing (almost) the original string back together. Perhaps you can elaborate on what you're trying to accomplish, and we can help you figure it out.

And to answer your original question, strings can be up to 2^31 - 1 length.

answered
0

check for $Message != empty

answered
0

Other improvement suggestions:

Note that $Message is not checked for null. Furthermore in the case colon is not found, find() will return -1, which will result in an out of bounds exception as well.

I think there is a more convenient way to express such a complex find/substring pattern by using regex replacements. But to translate the example above, it would be useful if you can explain what it does, because it is a bit hard to extract that from the expression given all the parenthesis.

answered