Select to view content in your preferred language

Remove Characters using Field Calculator

12699
6
12-30-2011 05:29 AM
StephanieMacuga
Occasional Contributor
Hi!

I've had this issue in the past, and don't think I've ever come up with a great way to resolve it other than doing a manual cut/paste for each field. 

I have one field of attributes that has an address and a direction (100 S Main St - 2NW; 1343 W Kimberly Rd - 3WSE; etc) and I need to calculate just the address portion (100 S Main St; 1343 W Kimberly Rd; etc) into a new field.  I know that I can use the Left/Mid/Right functions to remove a specific number of characters from a string, but my proplem is that that number will vary.  Is there any way that I can calculate only the characters to the left of the hyphen (as all attributes have the hyphen) into a new field?  Or by the same token, remove all characters to the right of, and including, the hyphen?

Thanks in advance!
Stephanie
6 Replies
KenBuja
MVP Esteemed Contributor
You can use Split to separate out the parts of the address. The syntax would be something like this:

addresses = Split([field], " - ")
address = addresses(0)
direction = addresses(1)
0 Kudos
Robert_LeClair
Esri Notable Contributor
Stephanie -

I'm not a VB Script or Python person and I'm sure there's some code that would do it easier than my suggestion.  There's the Standardize Addresses that breaks up your addresses into multiple fields.  From there you can create a new address field and concatenate the address fields you wish to keep into one field and delete the rest.

Good luck!

Robert LeClair
Esri-Denver
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Hi Stephanie,

Attached is an example on how to do this using the field calculator.  Make sure that 'Python' is checked at the top.  In the example, the values exists in a field called 'FullAddr', and I'm calculating the value to the left of the hypen to a field called 'Address'.  You can do the same for the text to the right of the hypen.  You will just need to change [0] to [1].
0 Kudos
BruceNielsen
Frequent Contributor
Stephanie,

You can extract just the address portion of your string with the Python statement:
address=input[:input.find("-")].strip()
where input is your original string with both address and direction.
StephanieMacuga
Occasional Contributor
Thanks to everyone for the suggestions!  I actually found an existing thread (eventually!!) that allowed me to do what I needed.  Using a combination of the Left and InStr functions as found in this post, http://forums.arcgis.com/threads/28351-VBScript-Left()-amp-InStr()-functions-ArcView-10, I was able to get what I needed!

Thanks again!
0 Kudos
JamesHood
Regular Contributor
I lifted this from elsewhere but very useful.

this is VB , not python

split on character - To split a field into a list
----------  In code Block ----------

dim splitList
dim value

splitList= split( [Feild1], ";")
if ubound(splitList) > 1 then 'if there's no comma, there's only one value in the splitList array and the next statement would error out
  value = splitList(0)
end if




----------  In Field =   ----------
value
0 Kudos