Remove text in parenthesis with Arcade

1649
4
Jump to solution
05-01-2019 11:55 AM
JoanHickey
New Contributor II

I have a python script to remove the text in parentheses for labeling, and I cannot figure out how to convert it to work with Arcade. (I did not write this script, but I am trying to get the same results in AGOL.

The Python script is: def FindLabel ( [label] :(
  S =[label].strip()
  i = S.find('(')
  if i == -1:
    return S.replace('::','\n')
  elif i > 0:
    return S[0:i]

I know that Arcade does not have a strip function, so I was trying trim, and instead of the newline function, I was just typing a space.

Example:  '82 (Globe)'  needs to be '82'

Thank you in advance.

Joan

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Honored Contributor

You can use the Arcade Split function.

var array = split($feature.field, "(")
return array[0]
‍‍‍

View solution in original post

4 Replies
KenBuja
MVP Honored Contributor

You can use the Arcade Split function.

var array = split($feature.field, "(")
return array[0]
‍‍‍

View solution in original post

JoanHickey
New Contributor II

That worked. Thank you so much!

Joan

0 Kudos
XanderBakker
Esri Esteemed Contributor

A small addition to the solution provided by Ken: if you are interested in returning a numeric value, you might want to explicitely convert it to a number. Also the text you return would have a space at the end, since split on "(" will result in an array with two elements: "82 " and "Globe)". To avoid this you could include the Trim and Number functions, like this:

var array = Split($feature.field, "(");
return Number(Trim(array[0]));
JoanHickey
New Contributor II

Got it. Thank you for the additional information.

Joan