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: ,

2
  • Are you using field calculator to populate your new field?
    – bluefoot
    Nov 15, 2012 at 15:44
  • yes, the VB script option
    – user12813
    Nov 15, 2012 at 16:14

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.