How to keep Code short?

Hello :slight_smile:

For the following string, I’m looking for a way to keep things neat and short :

if(${Q2}= ‘C1’, ‘E1’, if(${Q2}= ‘C2’, ‘E2’, if(${Q2}= ‘C3’, ‘E3’, ’ ')))

I can’t find the correct syntax yet, in order to wrap up C1 to C244 as well as E1 to E244.

I’m asking because my current case is dealing with 244 Cs and Es – and that would make a lots of brackets )))))))….

So, I started a few threads but had no luck with this particular point on expressing arrays.

Any precision would help a lot and would be much appreciated.

If your mapping is systematic: En = Cn, you only need to replace C with E.
You may try the translate() function, see Form Operators and Functions - ODK Docs and XML Path Language (XPath).

You could also use the string functions to do such replacement,e.g. concat() and substring(), see ODK XForms Specification.

1 Like