Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to use the Field Calculator (ArcMap (10)) to strip out double quotes in an address field (I didn't put them in there, believe me). I've tried many incantations but am still unable to even get off the ground with a calculation. yes, both fields are string, and both are of acceptable length.

This calculation: Sample calculation

Results in this:

fail

With this error message in the Results dialog:

error message

And I repeat, I didn't put them in there.

share|improve this question
1  
So you're copying them with the quotes in your test, did you already attempt stripping the quotes with something like !testing![1:len(!testing!)-1] –  Roy Jun 25 '12 at 18:30
    
The snippet you provided dies with the same message. –  valveLondon Jun 25 '12 at 20:20
add comment

6 Answers 6

up vote 14 down vote accepted

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('"', '')
share|improve this answer
    
Well, you got my hopes up, but that doesn't work for me. Neither the codeblock nor the straight up '!testing!' –  valveLondon Jun 25 '12 at 21:39
    
Hm, it worked on my 10.0sp4. May be it is because somewhere in your field there is actually single quote... Have you considered using UpdateCursor in python script? –  Alex Markov Jun 25 '12 at 21:52
2  
You know what? you're right, it does work. I hadn't had my 3:00 wake up juice. You win. –  valveLondon Jun 25 '12 at 22:03
    
I have managed to solve problem with a single quote. Check my update to the answer. –  Alex Markov Jun 25 '12 at 22:43
    
The Pre-Logic Script Code worked fine when used within a script - many thanks –  meryloo Sep 10 '13 at 21:09
add comment

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.

enter image description here

share|improve this answer
    
What is the magic trick here, your script did not work? –  artwork21 Jun 25 '12 at 18:50
    
This doesn't work. It looks like it should, but it doesn't. –  KevinMayall Jun 25 '12 at 18:50
    
Both of your fields are text correct? –  TurboGus Jun 25 '12 at 19:02
    
@Gus, Yes field is text. –  artwork21 Jun 25 '12 at 19:05
2  
I am not using 10.1. I am using 10.0 - that archaic version that is sooooo 2011. –  valveLondon Jun 25 '12 at 20:22
show 7 more comments

Here is a non script way to do it.

  1. Start edit session on you layer.
  2. Open up table and highlight field column.
  3. Select Table Options drop down arrow and select Find & Replace.
  4. Select Replace tab and enter Find what: ", select Replace all (you will have to click the Replace All button twice).
share|improve this answer
    
while I appreciate the possibility, I'm not only wanting to replace the double quotes and I'd rather work via scripting. –  valveLondon Jun 25 '12 at 20:19
add comment

I haven't tried this inside of Arc, but I was able to remove double quotes from a string in a Python IDE in this (quick) way:

aStr ='"test"'

a1 = aStr.lstrip('"')
a2 = a1.rstrip('"')

print a2

a2 prints test, without quotes.

share|improve this answer
    
I realize this doesn't help with the 'Find' portion of your question... –  Timothy Michael Jun 25 '12 at 21:22
add comment

A hybrid approach worked on my system:

'!testing!'.replace("\"","")
share|improve this answer
add comment

hi try using single quotes like this !test!.replace('"','')

share|improve this answer
    
Hi, this does not work. –  valveLondon Jun 25 '12 at 20:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.