2

I've searched on google intensively, must be missing something here: I only want to replace (in a string field) standalone zeros (len is 1 character), but the .replace function replaces all instances of 0.

How can I only replace a single character (meaning the value is simply 0). If the value is say 10004 or 02223 or 12450, leave alone.

string replace

2

Use the Show Codeblock option and use this function:

def replace_zero_string(value):
    if value == '0': # assuming the field is a text field
        return value.replace('0', '111')
    else:
        return value

Then outside/below the code block section call the function like:

replace_zero_string(!rpuid!)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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