How do I write an Arcade label expression to remove multiple (and inconsistent) leading characters from a field (e.g. !!**, ^^, ***)?

2974
8
Jump to solution
05-19-2020 03:45 AM
AmyEverett1
New Contributor II

I have users who populate a field that is used to label features on a map that is used by many other users.  I have no control over what/how they populate this field.  For whatever reason, several users insist on proceeding the actual value with arbitrary special characters such as !!**, !***, ^^**, *** (presumably for sorting purposes).  The end users of the data do not wish to see these characters when used as labels in commonly used maps and apps.  The leading characters differ all the time and I am having a hard time grasping how to replace multiple characters if/when needed. 

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi Amy Everett ,

I those characters always have to be removed no matter the position of these characters, you could use Replace. See the example below:

var txt = "!!**!***hello world^^*****";
txt = Replace(Replace(Replace(txt, "!", ""), "*", ""), "^", "");
return txt;

This will return "hello world".

If your use case is different, could you provide some examples to see what needs to be done?

View solution in original post

8 Replies
XanderBakker
Esri Esteemed Contributor

Hi Amy Everett ,

I those characters always have to be removed no matter the position of these characters, you could use Replace. See the example below:

var txt = "!!**!***hello world^^*****";
txt = Replace(Replace(Replace(txt, "!", ""), "*", ""), "^", "");
return txt;

This will return "hello world".

If your use case is different, could you provide some examples to see what needs to be done?

AmyEverett1
New Contributor II

Thank you, Xander!  That was exactly what I was looking for!  I didn't think about nesting them that way.  I appreciate your assistance!

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Amy Everett , 

Glad it works, but I want to emphasize what jborgion mentioned. Why do you have these characters in your data? Is there some part of the process you can change to avoid having these characters in your data?

JoeBorgione
MVP Emeritus

That's exactly what I've been wondering as well.  Sounds like a quick database tutorial for the users might be time well spent.

That should just about do it....
0 Kudos
AmyEverett1
New Contributor II

If I had any authority over the data structure, many things would be different!  Unfortunately I am just the recipient who has to make it come together in the end.  

XanderBakker
Esri Esteemed Contributor

Hi amy.b.everett , 

Thanks for clarifying. Sometimes we just have to work with the data that is provided to us. 

0 Kudos
JoeBorgione
MVP Emeritus

There are seldom good technological solutions to behavioral problems....  Ed Crowely

That should just about do it....
AlexRudowski
New Contributor III

I stumbled upon this thread when I was looking to remove part of a label from a feature field in a webmap. Here's what I ended up with:

//All labels are in Brighton with the same zip code. Expression removes town and zip code

var txt = $feature.Location
txt = Replace(txt, ", BRIGHTON, 84121", "");
return txt

 

AlexRudowski_0-1675961990856.png

Thanks!

0 Kudos