Dynamic Text - limiting characters to document name

738
2
06-14-2011 04:22 PM
RussellPilbeam
New Contributor
I've searched through the forum and couldn't find a similar question so apologies if this has already been answered before.

Within arcmap 10 looking at creating a specific map document id to display on the map layout made up of (first part of document name/company code/number field)

Its the first part of this id that i can not figure out. Example of a document name is abc123-file.mxd. What i would like to display is only abc123. Is there a way to amend the document name scripting to recognise the first part of the document name?
Tags (2)
0 Kudos
2 Replies
BruceNielsen
Occasional Contributor III
Assuming that the hyphen is always the separator that you're using, you can do it with the following:
filename.split('-')[0]
0 Kudos
RDHarles
Occasional Contributor
You could also use slicing:

x = "abc123-file.mxd"

# First 6 characters
print x[0:6]
>> abc123

# First 6 characters plus .mxd
print x[0:6]+".mxd"
>> abc123.mxd
0 Kudos