Select to view content in your preferred language

Inline Variable Truncate

1244
2
Jump to solution
07-31-2018 07:58 AM
EricStarn3
Emerging Contributor

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

0 Kudos
1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor

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:

Calculate Field and string slicing

To complete the expression click on the calculator button and complete as follows:

Building the expression

Note the parser type, code block the indentation in the script logic and your in-line variable is between double quotes.

View solution in original post

2 Replies
DuncanHornby
MVP Notable Contributor

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:

Calculate Field and string slicing

To complete the expression click on the calculator button and complete as follows:

Building the expression

Note the parser type, code block the indentation in the script logic and your in-line variable is between double quotes.

curtvprice
MVP Alum

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:])