1

I want to delete . , # in attribute table using field calculator (VB Script or Python).

How can I remove these using this example address: N. First St., Unit #1 (I don't need city or state name)

I checked several websites, but I couldn't find the clear answer.

How to remove comma from combined fields which should be null?

http://www.geospatialanalyst.com/search/label/field%20calculator

Ginny
  • 11
  • 2

4 Answers4

3

Use the built-in str.translate(table[, deletechars]), but with None for the table argument (requires at least Python 2.6). E.g.:

'N. First St., Unit #1'.translate(None, '.,#')

shows:

'N First St Unit 1'

Or for ArcGIS' calculator, this can be a one-liner:

!yourField!.translate(None, '.,#')
Mike T
  • 42,095
  • 10
  • 126
  • 187
1

Use python to calculate values in new field:

filter(lambda x: x not in ".,#", !yourField!)
FelixIP
  • 22,922
  • 3
  • 29
  • 61
1

in the python code block:

import re

def strip(value):
    return re.sub('[.,#]','',value)

and then in the field calculator:

strip(!fieldname!)
jmcbroom
  • 772
  • 5
  • 14
1

And another way.

Python Pre-Logic Script Code:

def remove(text):
    for char in [".", ",", "#"]:
        if char in text:
            text = text.replace(char, "")
    return str(text)

Bottom part:

remove(!yourField!)
ianbroad
  • 9,141
  • 4
  • 42
  • 88