Good morning.
I am not real savvy with field calculator. We have a couple fields that contain service address information. Someone opted to add additional information enclosed by parentheses in this field. I need to remove the parentheses and data within. Any advice or suggestions appreciated.
Thanks
Terry
Terry,
Using VBScript in the field calculator you just use Mid([yourfieldname], 1, (InStr([yourfieldname],"(") - 1))
This will look in the thread for the first occurance of "(" and take everything before the "(" and use it for the field calc.
Thank you Robert. I'll give it a shot.
Terry a little function for the field calculator
Python parser of course
expression box .... brace(!YourFieldNameHere!)
code block
def brace(fld):
"""replace brackets"""
a = ['[', ']', '{', '}', '(', ')']
for i in a:
fld = fld.replace(i, "")
return fld
of course you are putting the result in a new text field of appropriate width
Dan,
What about the data within?
I need to remove the parentheses and data within
ahh missed that bit
Thank you Dan.
What happened is when the service address got populated, someone added additional info between the parentheses in the same field, rather than using an address2 field
I don't need to save that info, just remove it.
Thank you
well the other function you might use.... but
Keep between the brackets
fld = "some stuff (the stuff) with more"
fld.split(")")[0].split("(")[1]
# yields
'the stuff'
# just replace fld with !YourFieldName!
Dump between the brackets
fld = "some stuff (the stuff) with more"
fld.split("(")[0].strip() + fld.split(")")[1]
'some stuff with more'
Using the Python interpreter, import the regular expression module (re) in the pre-logic script code block (click on Show Codeblock to open this):
import re
Then use a substitution along the lines of this:
re.sub(r"\([^\)]+\)", "", !ServiceAddr!)
Should work fine with multiple pairs of parentheses but will likely need to be tweaked if you've got nested pairs.
you missed the bit I did earlier... the stuff between the braces needs to be removed as well