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

168
7
Jump to solution
05-19-2020 03:45 AM
Highlighted
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. 

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
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

7 Replies
Highlighted
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

Highlighted
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!

Reply
0 Kudos
Highlighted
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?

Highlighted
MVP Esteemed Contributor

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

Reply
0 Kudos
Highlighted
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.  

Highlighted
Esri Esteemed Contributor

Hi amy.b.everett , 

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

Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

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