How to use multiple 'Replace' Arcade functions?

2316
2
Jump to solution
11-01-2018 02:49 PM
JosephFaliti
New Contributor II

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‌

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
StephenM
Occasional Contributor II

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')

 

View solution in original post

2 Replies
StephenM
Occasional Contributor II

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')

 

JosephFaliti
New Contributor II

Stephen M,

Thanks!  Works great!

0 Kudos