Use Attribute Rules to remove text from a field

2926
13
Jump to solution
11-05-2021 09:02 AM
Labels (1)
JustinBernard1886
New Contributor III

Hi all, 

I am extremely new at using attribute rules and Arcade for ArcGIS Pro, and I need some help on what I am sure is a simple process.

I have a column filled with text like this, "R4-52" and "H-R4-52" What I would like to do is use arcade to populate a new field where the output will be "R4", basically removing the dash and any characters before and after the dash. I know the replace function can be used to do this, but I wasn't able to find any examples.

Can someone help with this?

Much appreciated,

Justin

Tags (2)
0 Kudos
13 Replies
JoeBorgione
MVP Emeritus

Five minutes in the ESRI Arcade playground and I came up with this:

var name = ' R3-1';
Console(name)
var nameArray = Split(name,'-')
Console(nameArray)
var arrayLength = Count(nameArray)
Console(arrayLength)

if (arrayLength == 2) {
    Console(nameArray[0])
}

 

JoeBorgione_0-1636140938445.png

The Console() function is like the print() function in python, but it only works in the playground.  This is nothing more than python logic in Arcade...

That should just about do it....
0 Kudos
JustinBernard1886
New Contributor III

Hi All,

So I was able to find a solution that fit my needs. Thanks so much for all the help!

Justin

0 Kudos
JoeBorgione
MVP Emeritus

Care to share?

That should just about do it....
0 Kudos
JustinBernard1886
New Contributor III

Here:

(I did not write this)

var ZoneCodeName = $feature.CENTROID;
var ZoneCodeFndDash = Find('-', ZoneCodeName, 0);
var ZoneCodeFndLBracket = Find('(', ZoneCodeName, 0);
var Char1 = Mid(ZoneCodeName,0,1);
var Char2 = Mid(ZoneCodeName,1,1);
if (Char1=="H"){
var ZoneCodeCount = Count(ZoneCodeName);
var ZoneCodeName = Mid(ZoneCodeName, 2, ZoneCodeCount);
var ZoneCodeFndDash = Find('-', ZoneCodeName, 0);
var ZoneCodeFndLBracket = Find('(', ZoneCodeName, 0);
if (ZoneCodeFndDash!=-1){
var ZoneCodePre = Mid(ZoneCodeName, 0, ZoneCodeFndDash);
return ZoneCodePre;
}
if (ZoneCodeFndLBracket!=-1){
var ZoneCodePre = Mid(ZoneCodeName, 0, ZoneCodeFndLBracket);
return ZoneCodePre;
}
return ZoneCodeName;
}
if (ZoneCodeFndDash!=-1){
var ZoneCodePre = Mid(ZoneCodeName, 0, ZoneCodeFndDash);
return ZoneCodePre;
}
if (ZoneCodeFndLBracket!=-1){
var ZoneCodePre = Mid(ZoneCodeName, 0, ZoneCodeFndLBracket);
return ZoneCodePre;
}
return ZoneCodeName;

 

0 Kudos