AnsweredAssumed Answered

Replace character from attributes

Question asked by CCweedcontrol on Apr 27, 2017
Latest reply on May 2, 2017 by CCweedcontrol

I need to remove forward slashes from the attributes in a layer. I need to remove the first \ and last \ and replace the double \\ with just one \. I would appreciate any help. Thanks.

 

Currently the attributes looks like this.

\R2\\M1\

\M1\\M1\\C2\

\AG\\R2\\M1\\R2\

 

I need it to look like the following

R2\M1

M1\M1\C2

AG\R2\M1\R2

 

 

I tried the following but got error "TypeError: argument of type 'NoneType' is not iterable" on line if '\\' if '\\' in row[0]: #if a double quote is in the string returned.

 

with arcpy.da.UpdateCursor("In_memory\LayerTest", "ZONING_CODE") as cursor:
    for row in cursor:
         if '\\' in row[0]: #if a double quote is in the string returned, 
            row[0]=row[0].replace('\\','\\') #replace that double quote with an empty string (removes it) 
            cursor.updateRow(row)
    del row

Outcomes