Field calculations for adding spaces between values

1748
3
05-04-2018 12:47 PM
MatthewForsberg
New Contributor III

I need to clean up some attribute tables and I'm having some difficulty finding a way to fix a certain issue. I have columns that have strings such as "Curb spalling, 3ftx4ftx6ft," and want to add spaces. I want it to look like this; "Curb spalling, 3 ft x 4 ft x 6 ft." I'm not very good with editing attributes in this manner so I was wondering what I could do, rather than having to do every single row of the column manually..Thanks!

3 Replies
DarrenWiens2
MVP Honored Contributor

You can replace text in tables. I'd start by replacing "ftx" with " ft x ", and then tackle the other edge cases.

How To: Replace the text in multiple fields within an attribute table using the Find and Replace too... 

MatthewForsberg
New Contributor III

That's about the only thing I could figure out, haha. The other part of my question is actually the issue!

Thank you though!!!

XanderBakker
Esri Esteemed Contributor

If I use something like this (Python parser):

txt_in = 'Curb spalling, 3ftx4ftx6ft'
txt_out = txt_in.replace('ft', ' ft').replace('x', ' x ')

print txt_in
print txt_out

this will yield:

Curb spalling, 3ftx4ftx6ft
Curb spalling, 3 ft x 4 ft x 6 ft

So probably try and use:

!YourFieldName!.replace('ft', ' ft').replace('x', ' x ')

Test this, writing to a new field, rather than replacing the existing values.