Calculate Toolbox Tool: replace specific text

643
2
Jump to solution
11-27-2019 01:04 PM
KariBuckvold
Occasional Contributor

Hello all, I'm building a data cleanup tool in model-builder using the 'Calculate' field and the the .replace() function.  It's working well except for one problem, the values that I am updating are to include text string parts valuesin the original attributes.  So the replace function behaves as though there are endless wildcards in the field.  Is there a way to limit the replace function to change those field values where the first variable is as exactly as it is in the function 'Demo' vs '%Demo%'?  I figure it's got to be something easy I'm overlooking.

function:  !Project_Type!.replace('Demo','Demolition')

original value: Demo

intended value: Demolition

returned value: Demolitionlition

0 Kudos
1 Solution

Accepted Solutions
JoeMagnotta
New Contributor II

It seems like a band-aid, but you could add a conditional (if x like %demolition%) to not replace the same string more than once. Or, better yet, use conditionals to test if the replace function should run on a given value (if x == 'demo').

View solution in original post

0 Kudos
2 Replies
JoeMagnotta
New Contributor II

It seems like a band-aid, but you could add a conditional (if x like %demolition%) to not replace the same string more than once. Or, better yet, use conditionals to test if the replace function should run on a given value (if x == 'demo').

0 Kudos
KariBuckvold
Occasional Contributor

This was the casecracker!  I was trying to gather the group of values I wanted to change instead of using a conditional for a specific value.  Thanks Joe!

0 Kudos