604
5
05-13-2019 06:06 PM
by
New Contributor III

I'm wanting to recreate the below excel formula for labelling in a feature layer in Portal for ArcGIS v10.5.1. Is this possible using Arcade? I haven't found any similar functions to ISNUMBER?

=IF(ISNUMBER(FIND("-",C3)),RIGHT(C3,LEN(C3)-(FIND("-",C3)+1)),C3)

Tags (2)
1 Solution

Accepted Solutions
Esri Esteemed Contributor

Based on the test values you provided, the following expression will do:

``````var input = "XX00 - Test" // "XX02 - Test Avenue", "XXXA056 - Test Road", "Test Street", "XX56"
var array = Split(input, "-");
if (Count(array) == 2) {
return Trim(array[1]);
} else {
return Trim(array[0]);
}
‍‍‍‍‍‍‍``````

Obviously on line 1 you should point to the correct attribute using \$feature.NameOfField

Please test and see if the cases you provided describe all the situations that might occur in the data.

5 Replies
Esri Esteemed Contributor

You can use a combination of several functions in Arcade like shown below:

``````var txt = "abc-123.5def";
var exceptions = ["-", "."];
// Console(Number(txt));
var keep = "";
for (var i = 0; i < Count(txt); i++) {
var a = Mid(txt, i, 1);
// Console(i + ": " + a);
if (IndexOf(exceptions, a) != -1) {
keep += a;
// Console(" - Keep (1):" + a);
} else if (IsNan(Number(a)) == False) {
keep += a;
// Console(" - Keep (2):" + a);
} else {
// Console(" - Eliminating:" + a);
}
}

return Number(keep);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍``````

Obviously, this will fail completely in case you have something like "a-3bcd-65.32efd0.2". So, maybe you can provide some examples of what you have as input and what you are trying to obtain.

by
New Contributor III

Thanks Xander, here's an example of the type of data we have. Each item has an id e.g XX05 or a name or both. Ideally we would want only the name where available but if there's no name then the id will be used.

 Input Output XX00 - Test Test XX02 - Test Avenue Test Avenue XXXA056 - Test Road Test Road Test Street Test Street XX56 XX56
Esri Esteemed Contributor

Based on the test values you provided, the following expression will do:

``````var input = "XX00 - Test" // "XX02 - Test Avenue", "XXXA056 - Test Road", "Test Street", "XX56"
var array = Split(input, "-");
if (Count(array) == 2) {
return Trim(array[1]);
} else {
return Trim(array[0]);
}
‍‍‍‍‍‍‍``````

Obviously on line 1 you should point to the correct attribute using \$feature.NameOfField

Please test and see if the cases you provided describe all the situations that might occur in the data.

by
New Contributor III

That works well for the examples I provided, thanks Xander. I did notice some records have a double hyphen for example: XX000 - Test Avenue-Test District for those I would want everything after the first  ' - ' so I used a concatenate which seems to do the trick unless you have a more sophisticated way of doing this?

``````var input = \$feature.name
var array = Split(input, "-");
if (Count(array) == 2) {
return Trim(array[1]);
} else if (Count(array) == 3) {
return Concatenate(array[1],'-',array[2])
}
else {
return Trim(array[0]);
}
‍‍‍‍‍‍‍‍‍‍``````

Esri Esteemed Contributor

Just in case you could have situations with more than 3 elements when you split you text, you could do something like this:

``````var input = "XX000 - Test Avenue-Test District-Test"; // \$feature.name;
var array = Split(input, "-");
if (Count(array) == 2) {
return Trim(array[1]);
} else if (Count(array) > 2) {
var array2 = [];
for (var i in array) {
var part = Trim(array[i]);
if (i > 0) {
array2[Count(array2)] = part;
}
}
return Concatenate(array2,'-');
}
else {
return Trim(array[0]);
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍``````

This will create another array (array2) with all the elements but not the first one and than Concatenate that array with a dash.