Removing multiple characters from string field using Field Calculator Python Parser?
Even though this question can be considered off topic I though I would make a suggestion.
Try using the Python re module in the Field Calculator. Here is a simple example used in the ArcMap field calculator.
Pre-Logic Script Code
import re
def repChar(strg)
regexChars = '[!@$*#]'
line = re.sub(regexChars,'',x)
return line
Field
repChar(strg)
I know this isn't a very detailed excample but it's all I have time for at the moment.
It's not pretty, but
''.join([x for x in list(!file!) if x not in ["!","@","$"]])
should remove any single character you specify in the list, and return the resulting characters as a string (the "etc" in your example wouldn't work, however).
Your single line
!file!.replace(" ","")
can be added to by including more .replace()
!file!.replace(" ","").replace("?","").replace(",","").replace(chr(33),"")
and so on. You may need to escape some of the characters, or use their chr()
code if the field calculator doesn't like them. chr(33)
in my example replaces the !
.
Chr codes can be retrieved from: http://www.ascii-code.com/ or by opening the python window in ArcMap and typing ord("!")
, for example, or whatever character you want to find into ord()
.