Select to view content in your preferred language

Arcade Expression - Remove first 4 Characters from records, unless they contain the Prefix of 'MDU '

66
1
yesterday
Labels (1)
StephenDuncan
Emerging Contributor

Hi, 

I am new to Arcade Expressions and after some assistance with a query i have below:

 

I have a dataset that I would like to label using the label Expression in MapViewer.

Most of my data contains an attribute starting with 'MDU ', ( including a space after the MDU)  so I would like to remove this part of the record which I have managed to do with the expression below:

Right($feature.MDU_NAME, Count($feature.MDU_NAME) - 4)

 

So this is fine and works for all records starting with 'MDU' but removes the first 4 characters of records that do not contain MDU which is an issue, such as the record below High Speed 1.

  StephenDuncan_1-1746535862439.png

If anyone can help me with the IF statement to only apply the expression to records that 'MDU ' is present, that would be much appreciated.

Cheers,

Steve

 

0 Kudos
1 Reply
KenBuja
MVP Esteemed Contributor

This will remove "MDU " from your string if it contains it. Otherwise, the original string will be returned

var label = $feature.MDU_NAME
return iif(Left(label, 4) == 'MDU ', Mid(label, 4), label);