How to calculate a string with the value from the previous string

03-08-2021 05:10 AM
New Contributor

Dear all, please tell me, what code should I type in the calculator ArcGIS for fill strings with the value from the previous strings (from different columns)




0 Kudos
4 Replies
MVP Frequent Contributor

Would you also be wanting to add together 698 + 349, or just return the last number - 349, or the first - 698?

What is this table? It really seems a truly horrific way to store data.

0 Kudos
New Contributor

just return 698.- (as text)

Yes, I agry, it's terrible)))

0 Kudos
MVP Esteemed Contributor

There is no easy solution

The quickest would be to use

TableToExcel  Table To Excel (Conversion)—ArcGIS Pro | Documentation

fix the table up there then use

Excel To Table (Conversion)—ArcGIS Pro | Documentation

to bring the table back.

If that table is part of a feature class, then you will have to Join it to the original featureclass

... sort of retired...
MVP Frequent Contributor

It's very messy, but this should work (you'll have to enter the first value manually after).  I'm also not sure how it will cope with the logical test on empty strings rather than Null (None type) but we can adjust, or possibly export to a table which sets Null values.

pre-logic script code block

true_false = False
value = ''
def my_function(field1, field2):
    global true_false
    global value
    if field1:
        true_false = True
        return value
    elif true_false:
        value = field2
        true_false = False

Field3 =

my_function( !Field1!, !Field2!)