+ Reply to Thread
Results 1 to 7 of 7

Thread: Remove Characters using Field Calculator

  1. #1
    Stephanie Macuga
    Join Date
    Apr 2010
    Posts
    30
    Points
    3
    Answers Provided
    1


    0

    Default Remove Characters using Field Calculator

    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

  2. #2
    Ken Buja

    Join Date
    Jan 2010
    Posts
    1,212
    Points
    874
    Answers Provided
    151


    1

    Default Re: Remove Characters using Field Calculator

    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)
    Ken Buja
    Silver Spring, MD

  3. #3
    Robert LeClair

    Join Date
    Nov 2009
    Posts
    315
    Points
    111
    Answers Provided
    12


    1

    Default Re: Remove Characters using Field Calculator

    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

  4. #4
    Jake Skinner

    Join Date
    May 2010
    Posts
    1,598
    Points
    1122
    Answers Provided
    178


    0

    Default Re: Remove Characters using Field Calculator

    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].

  5. #5
    Bruce Nielsen
    Join Date
    Jan 2011
    Posts
    299
    Points
    130
    Answers Provided
    21


    0

    Default Re: Remove Characters using Field Calculator

    Stephanie,

    You can extract just the address portion of your string with the Python statement:
    Code:
    address=input[:input.find("-")].strip()
    where input is your original string with both address and direction.
    Last edited by bruce.nielsen; 01-03-2012 at 09:04 AM.
    GIS Specialist
    USDA-Natural Resources Conservation Service

  6. #6
    Stephanie Macuga
    Join Date
    Apr 2010
    Posts
    30
    Points
    3
    Answers Provided
    1


    1

    Default Re: Remove Characters using Field Calculator

    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/283...ons-ArcView-10, I was able to get what I needed!

    Thanks again!

  7. #7
    James Hood
    Join Date
    Apr 2010
    Posts
    89
    Points
    1
    Answers Provided
    1


    0

    Default Re: Remove Characters using Field Calculator

    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 ----------
    Code:
    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 = ----------
    Code:
    value

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts