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!

Hi,

If your variable contains elements separated by a space, you can treat it like the output of a select-multiple question. This means you can refer to the various elements using selected-at().

Might this be a workaround for you?

I’ve used a similar hack to fabricate a select-multiple question which can then be used as part of a choice-filter. For example, if during the demographics section of a survey, the enumerator entered 3 adult male and 1 infant male but no females in the household, later in the survey when the questions ask ‘which members of the household does this affect?’ the possible choices would be adult males and infant males, excluding females through choice-filter.

Hope this helps,

Hugh

···

On Monday, 21 August 2017 11:03:00 UTC+2, edoua...@gmail.com wrote:

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!

Hi Hugh,

Thanks for the idea but this would not work in my case as the content of my cell are not predefined (I have name, ID and a couple of additional info encoded in a QR code…).

I could handle part of this with substr and string-length but I miss a function that will give me the position of my separator within my string so that I could split and parse the various pieces…

I tried to use the expression position(xpath/to/value, pattern) but got:

The problem was located in calculate expression for ${QR1}\nXPath evaluation: cannot handle function 'position' requires either exactly one argument or no arguments.

Any other ideas?

I am not sure but it seems we can also write formula with Javascript method (https://www.w3schools.com/js/js_string_methods.asp ). Does this work with Kobotoolbox? If yes, how?

Thanks,
Edouard

···

Le lundi 21 août 2017 23:09:04 UTC+3, Hugh Earp a écrit :

Hi,

If your variable contains elements separated by a space, you can treat it like the output of a select-multiple question. This means you can refer to the various elements using selected-at().

Might this be a workaround for you?

I’ve used a similar hack to fabricate a select-multiple question which can then be used as part of a choice-filter. For example, if during the demographics section of a survey, the enumerator entered 3 adult male and 1 infant male but no females in the household, later in the survey when the questions ask ‘which members of the household does this affect?’ the possible choices would be adult males and infant males, excluding females through choice-filter.

Hope this helps,

Hugh

On Monday, 21 August 2017 11:03:00 UTC+2, edoua...@gmail.com wrote:

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!

Hi Edouard,

Sorry, perhaps I was unclear. It still seems to me that you can use selected-at(), even if the contents of the cell are generated from a QR code. KoBo doesn’t care what the source of the data is. If the string that the QR code produces is text separated by spaces, then it can still behave is if it is a select-multiple.

So in your case, selected-at(${QR_scan},0) would return the name, **selected-at(${QR_scan},1) ** would return the ID, etc.

There may well be other reasons you are not able to take this approach however, so forgive me if I’m not understanding quite why this approach isn’t feasible for you.

Best,

Hugh

···

On 22 August 2017 at 09:07, edouard....@gmail.com wrote:

Hi Hugh,

Thanks for the idea but this would not work in my case as the content of my cell are not predefined (I have name, ID and a couple of additional info encoded in a QR code…).

I could handle part of this with substr and string-length but I miss a function that will give me the position of my separator within my string so that I could split and parse the various pieces…

I tried to use the expression position(xpath/to/value, pattern) but got:

The problem was located in calculate expression for ${QR1}\nXPath evaluation: cannot handle function 'position' requires either exactly one argument or no arguments.

Any other ideas?

I am not sure but it seems we can also write formula with Javascript method (https://www.w3schools.com/js/js_string_methods.asp ). Does this work with Kobotoolbox? If yes, how?

Thanks,
Edouard

Le lundi 21 août 2017 23:09:04 UTC+3, Hugh Earp a écrit :

Hi,

If your variable contains elements separated by a space, you can treat it like the output of a select-multiple question. This means you can refer to the various elements using selected-at().

Might this be a workaround for you?

I’ve used a similar hack to fabricate a select-multiple question which can then be used as part of a choice-filter. For example, if during the demographics section of a survey, the enumerator entered 3 adult male and 1 infant male but no females in the household, later in the survey when the questions ask ‘which members of the household does this affect?’ the possible choices would be adult males and infant males, excluding females through choice-filter.

Hope this helps,

Hugh

On Monday, 21 August 2017 11:03:00 UTC+2, edoua...@gmail.com wrote:

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 received this message because you are subscribed to a topic in the Google Groups “Kobo Users” group.

To unsubscribe from this topic, visit https://groups.google.com/d/topic/kobo-users/rDMtoxhrD1I/unsubscribe.

To unsubscribe from this group and all its topics, send an email to kobo-users+unsubscribe@googlegroups.com.

To post to this group, send email to kobo-...@googlegroups.com.

Visit this group at https://groups.google.com/group/kobo-users.

For more options, visit https://groups.google.com/d/optout.