Find/Replace Double Quotes using Python Parser of ArcGIS Field Calculator?
I have found that in 10.0 Field Calculator is quite weird.
But I've managed to get it work. The main idea is to enclose field name with single quotes.
Example. let suppose we have fields text1
and text2
. Rather than Calculating field text2
with expression !text1!
, which probably will fail, try this one: '!text1'
. As you see I am using single quotes here.
So, back to your task. It will be more clear to use Pre-Logic Script Code:
def calc(value):
return value.replace('"', '')
Expression will be:
calc('!text1!')
I hope it will work for you.
I have not experimented further but I think that such weird behavior happens because field calculation is translated into the call to ArcToolbox tool CalculateField_management
and expression is provided as a parameter to it (probably additionally enclosed with single or double quotes).
UPDATE:
My previous solution will fail in case if there are single quotes in the values of field text1
.
Now I have managed to get it work both in case when there are chars '
and "
(single and double quotes) inside any value in attribute text1
.
Here is expression, which will return original string, supporting both types of quotes:
'''!text1!'''[1:-1]
For your task it can be extended to (without Pre-Logic Script Code):
'''!text1!'''[1:-1].replace('"', '')
If you are using version 10.1 and you are sure you want to get rid of every instance of double quotes you can use:
!testing!.replace("\"","")
If anyone knows why this works in 10.1 and not 10.0 I would be interested.
Here are the results entry from my run.
Here is a non script way to do it.
- Start edit session on you layer.
- Open up table and highlight field column.
- Select Table Options drop down arrow and select Find & Replace.
- Select Replace tab and enter Find what:
"
, select Replace all (you will have to click the Replace All button twice).