How Do I REMOVE X Characters From the Right Using Arcade?

1016
3
08-28-2020 08:33 AM
ChrisLope
New Contributor II

I finally have a new laptop and it's about to be a new fiscal year, so I am starting off my new GIS project with a clean slate--as in I'm kicking all my kludged together maps and bloated geodatabase with dozens and dozens of orphaned items to the curb.  I have been putting off using Arcade, but since I also plan on publishing more content to our portal, I want to start using it to make life easier for those online maps.

My current dilemma is that I can't figure out how to manipulate a label string the way I need to.  I have a field (Office Name) that includes the City and State.  To make labelling easier, I want to remove the last three characters in that field, which is a space and then the two character state abbreviation.  With Python, I can do it thusly:

def FindLabel ( [OFC_NM] 😞
L = [OFC_NM]
L = L.title()
L = L[:-3]
return L

How  the heck do I this (properly) with Arcade? 

arcade formatting‌ arcade language‌ string.format‌

0 Kudos
3 Replies
JoeBorgione
MVP Esteemed Contributor

There are Left, Mid, and Right functions.

can't wait to retire....
ChrisLope
New Contributor II

Thanks for the reply, Joe. Unfortunately those functions don't do what I need to be done, at least not as they are written/documented in the help file.  I actually played around with that prior to my post (should've mentioned that in my original post.)  

Although using the Left function would give me the characters to the left of the string, which is what I need, there is no consistent length to the office names. 

Python deals with this type of situation by allowing you to use negative numbers so using something like 

L = "New Orleans, LA" 
L[:-3]

gives you "New Orleans" when the string in the field is "New Orleans, LA".  I tried using the same logic with Arcade 

Right('New Orleans, LA', -3)

But that does not work and the labels don't actually render.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Chris Lope 

Have a look at this expression based on the suggestion by jborgion 

var txt = 'New Orleans, LA';
return Left(txt, Count(txt)-4);

This will return "New Orleans" (without the comma since it took off 4 characters)