Remove "County" from Arcade label of county names

394
4
Jump to solution
01-16-2024 01:59 PM
NicoleCarter
New Contributor II

New to Arcade, trying to remove some text from a label so it fits better. For example the labels are:

Iowa County

Wood County

Monroe County 

How do I write an arcade expression to remove "County" from each label?

0 Kudos
1 Solution

Accepted Solutions
LindsayRaabe_FPCWA
Occasional Contributor III

This would be my go to solution in the label expression:

Replace($feature.FieldName," County","")

For the reasons mentioned above, I would avoid the Split option. 

 

Lindsay Raabe
GIS Officer
Forest Products Commission WA

View solution in original post

4 Replies
ZachBodenner
MVP Regular Contributor

You could try using split:

 

 

Split($feature.labelfield, ' ')

 

 

I haven't used this one much, but if I read correctly, the first set of quotes with the space between will tell the Arcade renderer to use spaces as splits. You can also add a comma and then give it an integer value to specify the maximum number of splits.

 

Split($feature.labelfield, ' ', 1)

 

That might be helpful because it will for sure remove "County" from the return, but it might give you problems if a county has a two word name (ex. Otter Tail County" would just return "Otter.")

https://developers.arcgis.com/arcade/function-reference/text_functions/#split

 

Another option might be something like this: 

var txt = $feature.labelfield;
return Left(txt, Count(txt)-7)

If all the names are the same (County, which is 6 letters, plus a space before it) this should remove the final 7 characters of each name. This expression came from a similar ask on the community

PS sorry for a bunch of edits, I had ideas right after I hit submit!

SteveCole
Frequent Contributor

Someone else might have a more elegant solution but this should work:

var theInput = 'Alpha Bravo County';
var inputArray = Split(theInput, " ");

var theOutput = '';

for (var i in inputArray) {
  if (Upper(inputArray[i]) != 'COUNTY') {
    theOutput = theOutput + ' ' + inputArray[i];
  }
}

return Trim(theOutput);

 

I'm using the Upper function just to be safe in case there's any mix of upper / lower / proper case field values (but everyone is always consistent with attribute entry, amirite?)

Steve

ThomasHoman
Occasional Contributor III

Sorry, not on machine to do sample code. Why not just use the text replace function?

Replace('Monroe County', ' County', '')  Grab the leading space to County -> _County then replace with empty value

https://developers.arcgis.com/arcade/function-reference/text_functions/#replace 

LindsayRaabe_FPCWA
Occasional Contributor III

This would be my go to solution in the label expression:

Replace($feature.FieldName," County","")

For the reasons mentioned above, I would avoid the Split option. 

 

Lindsay Raabe
GIS Officer
Forest Products Commission WA