I need to remove whitespace from the end of a string in a field in ArcMap.
I tried first the VBA function RTrim, but whitespace still remained. I thought maybe the whitespaces were tabs, so I tried 'Replace([field], vbTab, ""), but no luck. Then I tried the Python function rstrip, as so:
!FIELDNAME!.rstrip()
..but this resulted in the whitespace being replaced by this character:
Â
There are several of these characters in each of the fields cells trailing the string. I have looked online for some meaning of this symbol, but I haven't found any. Doe anyone know what this means? I have still not successfully removed the trailing whitespace.
here is a screenshot of the attribute column after I run the Python code given above: enter image description here
-
2What is the underlying data source format? Shapefile, personal geodatabase, Excel?Hornbydd– Hornbydd2013年09月23日 17:06:59 +00:00Commented Sep 23, 2013 at 17:06
-
its a feature class stored in a file geodatabase. I am using ArcMap 10.0, and viewing in map/data in ArcMap/ArcCatalog with ArcViewJasonBK– JasonBK2013年09月23日 17:50:05 +00:00Commented Sep 23, 2013 at 17:50
-
1What is the original source of this data? Those types of characters usually indicate the data were actually encoded, like binary or something. How did it get into the file geodatabase? Also, your statement that the characters are in the field cells trailing each string is confusing. It would help to put up a screenshot of your data.Get Spatial– Get Spatial2013年09月23日 21:29:02 +00:00Commented Sep 23, 2013 at 21:29
-
I added a screenshot above (this is the result of running the Python code; the VBA code doesn't seem to do anything that I can see) ... Unfortunately I don't know much about how the data was collected; I would imagine the strings in this column were entered manually but I can't be sure...I will try to trace the source of the data and I will post if I find out.JasonBK– JasonBK2013年09月24日 13:10:54 +00:00Commented Sep 24, 2013 at 13:10
-
I found that the source of the data is an Excel spreadsheet, and the matching column also has whitespace trailing the string in this column...JasonBK– JasonBK2013年09月24日 20:39:58 +00:00Commented Sep 24, 2013 at 20:39
1 Answer 1
My co-worker came up with this ArcPy script that fixed the problem...it did require making a new field:
arcpy.AddField_management(featureClass, 'MainStreet', 'TEXT')
sCursor = arcpy.SearchCursor(featureClass)
for sRow in sCursor:
OID = sRow.OBJECTID
name = sRow.MainSt.encode('ascii', 'ignore')
query = '"OBJECTID" = ' + str(OID)
uCursor = arcpy.UpdateCursor(featureClass, query)
for uRow in uCursor:
uRow.MainStreet = name
uCursor.updateRow(uRow)
Explore related questions
See similar questions with these tags.