Hi,
I have an Arcade labeling expression that is using the Replace function. It works fine, but I have found that there are certain instances of the text that I don't want to replace.
If I add an additional Replace function, only the last one is honored. How can I resolve this issue?
What I have is like this:
Replace($feature.NAME + " Grades " + $feature.LO_GRD + "-" + $feature.HI_GRD, '0', 'K')
It works, but if a zero (0) is in the name field, it also is replaced with a 'K'.
I tried to add an additional statement to replace the new string that is wrong.
Like this:
Replace($feature.NAME + " Grades " + $feature.LO_GRD + "-" + $feature.HI_GRD, '0', 'K')
Replace($feature.NAME + " Grades " + $feature.LO_GRD + "-" + $feature.HI_GRD, '1K', '10')
But that is not working.
Any information you are willing to share would be much appreciated!
Thanks,
Joe
arcade expression
Solved! Go to Solution.
Each Replace returns a string, and the expression can only return one value, so I think that's why only the last Replace was honored. You could create a variable to store the string from the first Replace, then do a second replace based on that string.
Something like this:
var str = Replace($feature.NAME + " Grades " + $feature.LO_GRD + "-" + $feature.HI_GRD,'0','K')
Replace(str,'1K','10')
Each Replace returns a string, and the expression can only return one value, so I think that's why only the last Replace was honored. You could create a variable to store the string from the first Replace, then do a second replace based on that string.
Something like this:
var str = Replace($feature.NAME + " Grades " + $feature.LO_GRD + "-" + $feature.HI_GRD,'0','K')
Replace(str,'1K','10')
Stephen M,
Thanks! Works great!