I am using an inline variable substiution to alter a field name. I do this within an iteration model in model builder. The inline variable is the name of the feature class which I use as my input for each iteration. When I am altering the field name I would like to only use the first part of the inline variable. To explain this a bit better, here is the name structure of my feature classes:

  • SA_05_Walk_CBR
  • SA_10_Walk_CBR
  • SA_05_Bike_CBR
  • SA_10_Bike_CBR
  • SA_05_Driv_CBR
  • SA_10_Driv_CBR
  • SA_05_Walk_PJC
  • SA_10_Walk_PJC
  • SA_05_Bike_PJC
  • SA_10_Bike_PJC
  • SA_05_Driv_PJC
  • SA_10_Driv_PJC
  • etc.

(Note that all feature class names have the exact same amount of characters for each part of the names)

Within my iterator, these feature class names represent my inline variable substitution string (called "count_field" in my model, see picture).

When I use the iterator, I join all the SA_xx_xxxx with a point feature class where I use the last three letters of the feature class name as a wilcard (e.g. "star_CBR"). For my next iteration I do the exact same thing but then using "star_PJC" as my new wildcard. These iterations work fine without any problems and it is also the reason why my feature classes need to end with "*_xxx".

Next in my iteration, I alter a certain field name so that they can be differentiated within the table of the feature class. Currently I use this in-line variable subsitution to rename the field (e.g. "SJ_Count_%count_field%"). Also this process works fine. Here is a picture of the alter field window:

alter field window

(Please ignore the explanation mark; this picture is pure for a demo)

The thing what I want to do, however,is that it only uses part of the inline variable to alter my field name. The last 4 letters of my inline variable (e.g. "_CBR") can be removed within my new field name. So a field name would be called, for example, "SJ_Count_SA_05_Bike"

I have tried in renaming my field name again but I haven't found a way to remove the last 4 characters through an iteration. Anyone any ideas how I could do this in an efficient way? Using python within the alter field tool does not seem to be an option (as seen from alter field tool window picture). Here is a picture of my model:

join and alter field model through an iteration in model builder

1 Answer 1


Use the Calculate Value tool in model builder to drop the last 4 four characters of your Count_Field variable. Set the tool to be a precondition to the alter field tool to ensure it executes first.

Set your expression as shown below

Screen shot of Calculate Value Tool

  • Thank you so much! This worked out perfectly! Sometimes it can be so easy!
    – Jelle
    Commented Mar 2, 2015 at 16:58
  • I'm not familiar with the expression syntax. How would you remove the first four character, for example? Commented Oct 6, 2016 at 23:29
  • I figured it out... it is just a subsetting operation on the character string. In this case it would be "%count_field%"[4: ] where 4 is the number of characters from the beginning of the string after which to start, the colon indicates a 'range' and the empty second value in the range means 'to the end of the string'. Sorry for the beginner python question! Commented Oct 6, 2016 at 23:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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