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.
Solved! Go to Solution.
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?
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?
Thank you, Xander! That was exactly what I was looking for! I didn't think about nesting them that way. I appreciate your assistance!
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?
That's exactly what I've been wondering as well. Sounds like a quick database tutorial for the users might be time well spent.
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.
Hi amy.b.everett ,
Thanks for clarifying. Sometimes we just have to work with the data that is provided to us.
There are seldom good technological solutions to behavioral problems.... Ed Crowely
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
Thanks!
Dusted this off today. Still relevant. Super helpful!
Thank you!