parse text field in Field Calculator w/ VB or Python

402
2
05-10-2012 12:04 PM
deleted-user-ugCMpXci8bn5
New Contributor III
Hello,

I would like to create a new field by trimming the string from another field form a given set of characters..

For example:
1 HOUR PARKING 10AM-7PM EXCEPT SUNDAY (ARROW)(SUPERSEDED BY SP-133EA)

would be trimmed at "(SUPERSEDED..."
to become
1 HOUR PARKING 10AM-7PM EXCEPT SUNDAY (ARROW)

in the new field.
I currently have this VB statement in the pre-logic block:
s = Instr (1, [SignDesc1] , "SUPERSEDED BY")

with this statement below in the code:
Left ( [SignDesc1], s)

This results in a new field with
1 HOUR PARKING 10AM-7PM EXCEPT SUNDAY (ARROW)(S

and several SQL errors.

I think at least one problem is I am having trouble with the '(' character..I have tried a few escape character methods (using '\', or double quotes) but none have worked...

Any ideas? Thanks! // Jason
0 Kudos
2 Replies
LeonardWilliamson
New Contributor III
This is the python way.

sIn = "1 HOUR PARKING 10AM-7PM EXCEPT SUNDAY (ARROW)(SUPERSEDED BY SP-133EA)"
sOut = sIn.rsplit("(SUPERSEDED", 1)[0]
0 Kudos
deleted-user-ugCMpXci8bn5
New Contributor III
Thanks..I realized mine could work also, bu just adding (s-2) to move the parse over two characters....
0 Kudos