Select to view content in your preferred language

substring using specific character search

412
1
11-02-2023 04:04 PM
AndreaPecharich
New Contributor II

I am looking for a way to return a substring from a text field based on a specific value within the text string. The S123 form has a text field 'pitnumber_raw' that receives data from an RFID tag. The text string is something like '09-05-2023 14:27:27 03 TAG 3DD.003D95537C' and the desired result is 14 characters, 3DD.003D95537C. The problem I am having with the regular substring function is that the length of the initial text string is variable, some mobile devices running the S123 form place an invisible carriage return at the end of the string, and some do not.  Is there a way to select the start of the substring statement based on values within the text string?

In excel the formula would look like =TRIM(MID([pitnumber_raw], SEARCH("3DD.",[pitnumber_raw]),14)) 

0 Kudos
1 Reply
IsmaelChivite
Esri Notable Contributor

Hi @AndreaPecharich Here is a JS function equivalent to your excel formula above.

function parse3DD(arg1) {
    var trimmed = arg1.trim();
    var idx = trimmed.indexOf('3DD');
    return trimmed.substring(idx,idx + 14);
}

Check this for details on how to use JS functions in XLSForms: https://community.esri.com/t5/arcgis-survey123-blog/extending-survey123-smart-forms-with-custom-js/b... 

 

0 Kudos