6

I have Drivers License as one field and State as the other and there are to be combined and formatted as Drivers License, State. How do I handle records that do not have either a Drivers License or State so that the field does not have a comma populated in it

Example:

Record One: XXXXXX, ST

Record Two: ,

Record Three: XXXXX, ST

Record Four: ,

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
user12813
  • 61
  • 1

1 Answers1

13

You can use a regular expression.

In ArcGIS, go to the Field Calculator. For safety's sake run it on a new column.

Set to python.

Pre-logic script code:

import re
def my_regex(s):
    return re.sub("^,", "", s)

Name =

my_regex ( !Column_Name! )

Replace Column_Name with the name of the column you want to strip the , from.

Field Calculator dialog

This will strip the comma if, and only if, it is the first character in the field. It will ignore following characters. So:

XXXXXX, ST = unchanged

, becomes blank

, ST = becomes ST (including leading space)


To do it with VB Script (the regex will be the same): VBscript Regular Expression in ArcMap Field Calculator

GIS-Jonathan
  • 6,775
  • 5
  • 29
  • 58