Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

share|improve this question
    
Are you using field calculator to populate your new field? –  egdetti Nov 15 '12 at 15:44
    
yes, the VB script option –  user12813 Nov 15 '12 at 16:14
add comment

1 Answer

You can use a regular expression.

In ArcGIS, go to the Field Calcuator. For safetys 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.

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)


Edit - how to do it with VB Script if you get bored or something (the regex will be the same): VBscript Regular Expression in ArcMap Field Calculator

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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