Substring-after - parsing a string with calculate

Hi,

I need to parse the content of a variable recorded through a barcode. Basically I have a list of ordered elements in the same variable separated by space that I want to re-use in the form after.

I can see that Javarosa only includes the following string functions:
substr
string-length

How can I get the equivalent of the x-path functions
substring-after and
substring-before ?

If not, is there a smarter way to do what I need to do?

Thanks!

You can do this with regex(value, expression). You'll just have to construct the regex instead; so if we wanted to search for xyz with substring-after we would do: regex(., 'xyz(.*)$'), and the equivalent for -before would be regex(., '^(.*)xyz').

If you are not familiar with regexes (regular expressions), there are many tutorials online; I won't link one only because I don't know which ones are the best. Or, you can post here what you are looking to accomplish and we can help you out.

How the examples I posted work is by sandwiching a capture group that accepts any number of any characters between the text you are looking for (xyz) and the start (^) or end ($) of the string. This forces the expression to capture all of the text in between. But if you are looking for text that isn't simply letters, you may run into trouble as there are a lot of special characters that do special things in regex.

2 Likes

Thanks for the solutions.
The regex function returns true/ false value, how do I extract the value before/ after instead?

Thank you