Pro - Arcade Labeling - Replace & Concatenate

1446
5
Jump to solution
03-29-2021 08:30 AM
JessicaJThompson
Occasional Contributor II

Hello!

New to arcade & pro (and fairly terrible at code). Thank you in advance for you kindness & assistance.

I have pieced together a few things from other posts, but am still having issues. I have a request to replace labels in a map on data I cannot and do not want to edit. I just want to change the acronym used in the data to the desired label.

1) I am currently using the concatenate command, which is working.  

Concatenate($feature.FD,'-',$feature.Station)

JessicaThompson1_0-1617029877021.png

2) I need to replace the $feature.FD label 'SF&ES' with 'SFD' in that field. When I try the replace command

Replace($feature.FD, "SF&ES","SFD")

It does work but I cannot get the two commands to work together correctly

JessicaThompson1_2-1617031213422.png

3) When combined:

Replace($feature.FD, "SF&ES","SFD")+
Concatenate($feature.FD,'-',$feature.Station)
JessicaThompson1_1-1617031002928.png

Or in reverse order

Concatenate($feature.FD,'-',$feature.Station)+
Replace($feature.FD, "SF&ES","SFD")

JessicaThompson1_3-1617031591705.png

0 Kudos
1 Solution

Accepted Solutions
SarahHartholt
Occasional Contributor III

I would set a variable first to pass the new ID and then concatenate:

 

var label = Replace($feature.FD, "SF&ES","SFD")
return Concatenate(label,'-',$feature.Station)

 

View solution in original post

5 Replies
SarahHartholt
Occasional Contributor III

I would set a variable first to pass the new ID and then concatenate:

 

var label = Replace($feature.FD, "SF&ES","SFD")
return Concatenate(label,'-',$feature.Station)

 

JessicaJThompson
Occasional Contributor II

Thank you! Super helpful! I was able to return the product quickly without having to dive into the material, which I will start doing. Do you have any recommendations - tutorials, sources?

0 Kudos
SarahHartholt
Occasional Contributor III

ESRI training videos were a good starting point for me (Esri Training Catalog | Find Courses on GIS and ArcGIS Topics), just type in arcade! I also browse the community forums to see what others have struggled with and test out code in the arcade playground (ArcGIS Arcade | ArcGIS for Developers).

0 Kudos
jcarlson
MVP Esteemed Contributor

It's important to note that calling Replace does not actually change the value stored in $feature.FD, so calling that attribute elsewhere will always return the unreplaced value.

To accomplish what you're trying to do, you can either nest your functions, or else use a temporary variable.

var fd = Replace($feature.FD, "SF&ES", "SFD")

Concatenate(fd,'-',$feature.Station)

 Or

Concatenate(Replace($feature.FD, "SF&ES", "SFD"), '-', $feature.Station)

Myself, I prefer using variables to keep the code a bit easier to read.

- Josh Carlson
Kendall County GIS
JessicaJThompson
Occasional Contributor II

Appreciate you taking the time to provide to options, and the extra information on why it may not change using the replace command! Cheers!

0 Kudos