Select to view content in your preferred language

Use Attribute Rules to remove text from a field

4168
13
Jump to solution
11-05-2021 09:02 AM
JustinBernard1886
Occasional Contributor

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
1 Solution

Accepted Solutions
JustinBernard1886
Occasional Contributor

Hi All,

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

Justin

View solution in original post

0 Kudos
13 Replies
JoeBorgione
MVP Emeritus

What about the left() function?

That should just about do it....
0 Kudos
JayantaPoddar
MVP Esteemed Contributor

Are you looking for the exact value, 'R4'?

Then, check the following syntax

Parser: Arcade

IIF(FIND('R4',$feature.FIELDNAME,0)==-1,'','R4')

 

 Let me know a few more examples if the substring value is dynamic.



Think Location
0 Kudos
JustinBernard1886
Occasional Contributor

Thanks for the reply!
The values are dynamic, my apologies. 
I basically would like to remove the <text>"-" , "-'<text> and keep the middle characters.
Thanks for the help!

0 Kudos
JayantaPoddar
MVP Esteemed Contributor

Do you have one "-" or more than two "-" instances in the string? What to do in those cases?

e.g.: HE-77-L-0



Think Location
0 Kudos
JustinBernard1886
Occasional Contributor

Just one and two dashes
eg: R3-1, and H-R4-2

 

0 Kudos
JayantaPoddar
MVP Esteemed Contributor

Parser: Arcade

 

SPLIT($feature.FIELDNAME,'-')[-2]

 

 



Think Location
0 Kudos
JoeBorgione
MVP Emeritus

I thought this is in the context of an Attribute Rule; in that case Arcade is the only option.

That should just about do it....
0 Kudos
JayantaPoddar
MVP Esteemed Contributor

Ahh. I see. Removed the Python one.

Thanks.



Think Location
0 Kudos
JoeBorgione
MVP Emeritus

Another approach:  split the string at the dashes into an array and then get the count of that array.  If the count indicates 1 dash, grab the first element of the array; if the count indicates 2 dashes, grab the second element of the array.  I'm pretty sure arcade arrays are 0 based.

That should just about do it....
0 Kudos