Hello All,
So I have a model that Iterates through a GDB and then strip out unwanted fields and then adds a field and populates it with the name of the origin feature class. This works as expected. However, what I would like to do is run the "Calculate Field" tool and still use the inline variable but remove the first part of it. (i.e. Site_26105 to 26105).
How can I accomplish this?
Respectfully,
Eric
Solved! Go to Solution.
You achieve this by python string slicing. So assuming all your input featureclass names are always the format of "Site_1234" then your field calculate tool need only be this:
To complete the expression click on the calculator button and complete as follows:
Note the parser type, code block the indentation in the script logic and your in-line variable is between double quotes.
You achieve this by python string slicing. So assuming all your input featureclass names are always the format of "Site_1234" then your field calculate tool need only be this:
To complete the expression click on the calculator button and complete as follows:
Note the parser type, code block the indentation in the script logic and your in-line variable is between double quotes.
Duncan's great example was done using a code block so he could comment it so awesomely, but it should be noted you can put the Python expression right in the main expression block (no code block function required) as:
"%Name%"[5:]
or
"%Name%".replace("Site_","")
Also, if "Site" is an integer field you would need to "int" the result (unlike the VB parser, you need to make sure the datatype matches):
int("%Name%"[5:])