string regex manipulation help needed

0
i have a text in a variable, and need to print 1 line above a text “Error” , so i get the items that are erroring. what tools , add-ons  to use so i get below output  Item4 Item5   from   Item1 Good Item2 Good Item3 Good Item4 Error Item5 Error Item6 Good
asked
2 answers
0

You can do this with XPath and do retrieve only on those items that have the text attribute "Erorr".

 

answered
0

All can be done with string function calls: https://docs.mendix.com/refguide/string-function-calls/

Use the find method to get the location of Error. So

find($stringtosearch, 'Error')

 

The result would be 47. Now you wanted the string before the error so now find the position of Good. Since you need the last occurance of Good before 47 you could use substring for that. We already now the length of the string we want (47) so just use the following command. Note that 0 means start from the biginning.

substring($stringtosearch, 0,47)

 

You can then use findLast to get the last position of Good.  You can then use substring again but instead of 0 use the value of the position of Good plus 4 for the length of Good to get the result you want.

This way you can cut your  string up untill there are no Errors in you string anymore.

Regards,

Ronald

 

answered