1

I'm trying to get a part of a string (numbers after letter) in a new table (field Description) using field calculator, but I need it only from a field next to it (field MUID) containing the first letter "P" while the rest, that contains something else will be null.

That means if MUID = P14 then Desc = 14 or MUID = P1 then Desc = 1 and if MUID = HT9 then Desc = 0.

Is there a way to write it in the Python parser?

Will need it in the future to implement it via ModelBuilder.

I tried to use this, but it keeps getting Error signs

enter image description here

1 Answer 1

1

Try this using python parser:

def nums(textfield):
    if textfield[0]=='P': #If first letter is P
        newval = ''.join([n for n in textfield if n.isnumeric()]) #List all numbers and join them together to a string
        try: #If there is no integer this will prevent the code from breaking
            int(newval)
            return newval
        except ValueError: #Dont return / return NULL if there is no number
            pass

enter image description here

0

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.