Getting the char at a specific index works with some string, but not with others

I’m working on a bot where I read the subject of an email, and I need to parse the word between the word “Example1” and the word “-” and save it in a variable that will be used later, I call this variable “project”. This project variable starts with letters, then it follows with numbers, and I need the letters in a variable “prefix”. For this, I used a loop that would cycle through each character using the expression ${project[${counter}]} while it is a letter and add the char to “prefix”. I tried It giving the project a default value and it worked fine, but if the variable project is derived from the parsing of the subject of the email, the expression ${project[${counter}]} just doesn’t return any value. The logs even show the parsing was correct and “project” has the value it should have. If I use the split string with “Example1” it works fine so this is specific when obtaining the value of the string with substring between function. I know this bug is low priority as it’s workaround is pretty simple(3 more actions) but still, shouldn’t happen.

Hi @m.landos1 can you share a recording example where it doesn’t work so we could test it?

index-bug-example.zip (841 Bytes)
you can see the strings parsed1 and parsed2 share the same value, but one returnas the char invoked, the other doesn’t

1 Like

Thank you @m.landos1 we’ll test and return to you shortly.

Hi @m.landos1 it happens because of the space between words.

In the first example, whitespace is trimmed in the Split String actions, so ${parsed1[1]} returns “o”.
In the second one, ${parsed2[1]} returns whitespace. If you add a Trim Whitespace action, it should work correctly.

Let me know if it doesn’t work!

It does work, thanks. Seem like my loop of extracting every char while it is letter didn’t work because i was using regular expression [a-zA-Z], but it didn’t even enter the first iteration since the white space didn’t match that regexp. As an improvement, could the logs show the whitespaces at the beggining and end of a string?

Thank you for the suggestion @m.landos1