Arcade expression to find text in string and assign value

3206
2
Jump to solution
04-07-2019 10:18 PM
CraigPoynter
Occasional Contributor III

Hi,

I have a field that I wish to assign classes too (e.g. ABC123 - W - 201930 - 4/03/2019 to 21/06/2019 - D). I wish to search the text string using Arcade, so that I can classify my data into three unique classes.

I have found the 'Find' function, but unsure about how to use it correctly.

var placement = When(


Find('ABC123', $feature["USER_Unit_Offering_Display_Text"]),'Field 1',
Find('DEF456', $feature["USER_Unit_Offering_Display_Text"]),'Field 1',
Find('GHI789', $feature["USER_Unit_Offering_Display_Text"]),'Field 2',
Find('JKL012', $feature["USER_Unit_Offering_Display_Text"]),'Field 2',
Find('MNO345', $feature["USER_Unit_Offering_Display_Text"]),'Field 2 (Ongoing)', ' '
)

return placement;

Any ideas please?

Regards,

Craig

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

You could try something like this:

var disp_txt = $feature["USER_Unit_Offering_Display_Text"];

if (Find("ABC123", disp_txt, 0)>-1) {
return "Field 1";
} else if (Find("DEF456", disp_txt, 0)>-1) {
return "Field 1";
} else if (Find("GHI789", disp_txt, 0)>-1) {
return "Field 2";
} else if (Find("JKL012", disp_txt, 0)>-1) {
return "Field 2";
} else if (Find("MNO345", disp_txt, 0)>-1) {
return "Field 2 (Ongoing)";
} else {
return "Other";
}

If the function Find does not find the specified string it will return the value -1

View solution in original post

2 Replies
XanderBakker
Esri Esteemed Contributor

You could try something like this:

var disp_txt = $feature["USER_Unit_Offering_Display_Text"];

if (Find("ABC123", disp_txt, 0)>-1) {
return "Field 1";
} else if (Find("DEF456", disp_txt, 0)>-1) {
return "Field 1";
} else if (Find("GHI789", disp_txt, 0)>-1) {
return "Field 2";
} else if (Find("JKL012", disp_txt, 0)>-1) {
return "Field 2";
} else if (Find("MNO345", disp_txt, 0)>-1) {
return "Field 2 (Ongoing)";
} else {
return "Other";
}

If the function Find does not find the specified string it will return the value -1

View solution in original post

CraigPoynter
Occasional Contributor III

Thank you Xander,

Code example you have provided worked excellent.

Regards,

Craig