<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Remove extra spaces from string using the field calculator in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274134#M21203</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Am I missing something in this code?&amp;nbsp; It seems like this would just "strip" the whitespace from the ends and still leave all the internal spaces?&lt;BR /&gt;&lt;BR /&gt;R_&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, only the whitespace from the ends get stripped with this code and the internal spaces are still present.&amp;nbsp; I am using this code against file and personal geodatabases.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 26 Jul 2013 14:06:55 GMT</pubDate>
    <dc:creator>CraigPrisland</dc:creator>
    <dc:date>2013-07-26T14:06:55Z</dc:date>
    <item>
      <title>Remove extra spaces from string using the field calculator</title>
      <link>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274125#M21194</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi, I'm looking for an elegant python expression that I can be used within ArcMap's field calculator to find all instances of consecutive spaces within a string and replace them with a single space.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Example: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]Let's say in a field called "&lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;Address&lt;/SPAN&gt;&lt;SPAN&gt;" we have the following value (the product of poor concatenation):[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]"&lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;&lt;STRONG&gt;_123_____Main__St,____Townsville,______CA_98463___&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt;"[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]It should become "&lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;&lt;STRONG&gt;123 Main St, Townsville, CA 98463&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt;"[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I know that .strip will get rid of the leading/trailling spaces.&amp;nbsp; How to I get a find/replace approach to continue looping through until all the double-spaces have been reduced to single spaces?&amp;nbsp; Also, I have tried using &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;&lt;STRONG&gt;.split&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt;, but get an error in ArcMap that "Field is not Nullable".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Dec 2011 15:14:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274125#M21194</guid>
      <dc:creator>MattGoodman</dc:creator>
      <dc:date>2011-12-19T15:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: Remove extra spaces from string using the field calculator</title>
      <link>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274126#M21195</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fieldvalue=' '.join(fieldvalue.strip().split())
#in case fieldvalue=='', change empty string to space to avoid "Field is not Nullable" error
if not fieldvalue: fieldvalue=' '&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:22:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274126#M21195</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2021-12-11T13:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: Remove extra spaces from string using the field calculator</title>
      <link>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274127#M21196</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have been using this Python script on one field at a time using the Field Calculator and it is working very well, thank you.&amp;nbsp; What I am now looking for is to see if there is a Python script that could be run that would look at all fields in a particular feature class and remove any extra spaces in any of those fields.&amp;nbsp; Any assistance would be greatly appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you in advance.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Jul 2013 12:55:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274127#M21196</guid>
      <dc:creator>CraigPrisland</dc:creator>
      <dc:date>2013-07-24T12:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: Remove extra spaces from string using the field calculator</title>
      <link>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274128#M21197</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Craig,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You could accomplish this with the following code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
fc = "Parcels"

for field in arcpy.ListFields(fc, "*", "String"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(fc, field.name) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value = row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value = str(value).rstrip()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[0] = value
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)

del cursor&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:22:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274128#M21197</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T13:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: Remove extra spaces from string using the field calculator</title>
      <link>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274129#M21198</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Jake,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the quick response and script.&amp;nbsp; I tried using this script that you provided by replacing "parcels" with the path to my feature class.&amp;nbsp; I then added this script into ArcToolbox and ran it.&amp;nbsp; The ran successfully, but when I opened the feature class, the extra spaces did not appear to get removed.&amp;nbsp; Is there anything else that I am missing?&amp;nbsp; Thanks again!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Jul 2013 15:42:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274129#M21198</guid>
      <dc:creator>CraigPrisland</dc:creator>
      <dc:date>2013-07-25T15:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: Remove extra spaces from string using the field calculator</title>
      <link>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274130#M21199</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Did you reload the fc after the script?&amp;nbsp; Perhaps you should be working with fc's loaded in as layers rather than running fc from a file on disk&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Jul 2013 17:27:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274130#M21199</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2013-07-25T17:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: Remove extra spaces from string using the field calculator</title>
      <link>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274131#M21200</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi Jake,&lt;BR /&gt;&lt;BR /&gt;Thanks for the quick response and script.&amp;nbsp; I tried using this script that you provided by replacing "parcels" with the path to my feature class.&amp;nbsp; I then added this script into ArcToolbox and ran it.&amp;nbsp; The ran successfully, but when I opened the feature class, the extra spaces did not appear to get removed.&amp;nbsp; Is there anything else that I am missing?&amp;nbsp; Thanks again!&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You said that post 2 worked for you, but only on a single feature.&amp;nbsp; You can combine the two and use that same coding on the entire FC if you want.&amp;nbsp; something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
arcpy.MakeFeatureLayer_management("C:/data.gdb/parcels", "parcels_lyr")


for field in arcpy.ListFields("parcels_lyr", "*", "String"):

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sqlFieldName = arcpy.AddFieldDelimiters("parcels_lyr", field)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; calcSql= "' '.join( field.strip().split())"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management("parcels_lyr",field,calcSql,"PYTHON_9.3","#")




&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This seems to do it for me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you wanted to use cursors, post 4 could be used, but use this calc function instead.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:22:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274131#M21200</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2021-12-11T13:22:50Z</dc:date>
    </item>
    <item>
      <title>Re: Remove extra spaces from string using the field calculator</title>
      <link>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274132#M21201</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi Jake,&lt;BR /&gt;&lt;BR /&gt;Thanks for the quick response and script.&amp;nbsp; I tried using this script that you provided by replacing "parcels" with the path to my feature class.&amp;nbsp; I then added this script into ArcToolbox and ran it.&amp;nbsp; The ran successfully, but when I opened the feature class, the extra spaces did not appear to get removed.&amp;nbsp; Is there anything else that I am missing?&amp;nbsp; Thanks again!&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Are you working with an SDE, File, or Personal Geodatabase?&amp;nbsp; If you are working with an SDE feature class, you may have to refresh the version using the Refresh tool on the Versioning toolbar.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Jul 2013 18:33:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274132#M21201</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2013-07-25T18:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: Remove extra spaces from string using the field calculator</title>
      <link>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274133#M21202</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi Craig,&lt;BR /&gt;&lt;BR /&gt;You could accomplish this with the following code:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
fc = "Parcels"

for field in arcpy.ListFields(fc, "*", "String"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(fc, field.name) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value = row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value = str(value).rstrip()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[0] = value
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)

del cursor&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Am I missing something in this code?&amp;nbsp; It seems like this would just "strip" the whitespace from the ends and still leave all the internal spaces?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:22:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274133#M21202</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2021-12-11T13:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: Remove extra spaces from string using the field calculator</title>
      <link>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274134#M21203</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Am I missing something in this code?&amp;nbsp; It seems like this would just "strip" the whitespace from the ends and still leave all the internal spaces?&lt;BR /&gt;&lt;BR /&gt;R_&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, only the whitespace from the ends get stripped with this code and the internal spaces are still present.&amp;nbsp; I am using this code against file and personal geodatabases.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Jul 2013 14:06:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274134#M21203</guid>
      <dc:creator>CraigPrisland</dc:creator>
      <dc:date>2013-07-26T14:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: Remove extra spaces from string using the field calculator</title>
      <link>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274135#M21204</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I know this is asking for a python method, but just in case it helps someone, the VB Script method to strip out all double spaces and any leading or trailing spaces is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Output = [MyField] ' Replace MyField with the actual text field name
If Not IsNull(Output) then
&amp;nbsp; Output = Trim(Output)
&amp;nbsp; If Output &amp;gt; "" Then
&amp;nbsp;&amp;nbsp;&amp;nbsp; Do While InStr(1, Output, "&amp;nbsp; ")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Output = Replace(Output, "&amp;nbsp; ", " ")
&amp;nbsp;&amp;nbsp;&amp;nbsp; Loop
&amp;nbsp; Else
&amp;nbsp;&amp;nbsp;&amp;nbsp; Output = " "&amp;nbsp; ' Avoid Field Is Not Nullable Error
&amp;nbsp; End If
Else
&amp;nbsp; Output = " "&amp;nbsp; ' Field allowed Nulls, use of this option replaces them with white space.
End If&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:22:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274135#M21204</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-11T13:22:55Z</dc:date>
    </item>
    <item>
      <title>Re: Remove extra spaces from string using the field calculator</title>
      <link>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274136#M21205</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fieldvalue=' '.join(fieldvalue.strip().split())
#in case fieldvalue=='', change empty string to space to avoid "Field is not Nullable" error
if not fieldvalue: fieldvalue=' '&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I've been trying to set this up in the Field Calculator dialog, but I'm obviously missing something.&amp;nbsp; Thus far, all I've achieved is a syntax error message.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My situation is very similar to what Matt Goodman originally posted on 12-19-2011.&amp;nbsp; In my case, the field from which I want to remove extra spaces is entitled &lt;/SPAN&gt;&lt;STRONG&gt;MailAddres&lt;/STRONG&gt;&lt;SPAN&gt;.&amp;nbsp; What should I enter for the &lt;/SPAN&gt;&lt;STRONG&gt;Expression&lt;/STRONG&gt;&lt;SPAN&gt; &amp;amp; &lt;/SPAN&gt;&lt;STRONG&gt;Pre-Logic Script Code&lt;/STRONG&gt;&lt;SPAN&gt; fields to make this work?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe a more fundamental question is: is there a Python equivalent to the TRIM(text) function found in MS Excel?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Christopher J. Morneau&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:22:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274136#M21205</guid>
      <dc:creator>ChristopherMorneau</dc:creator>
      <dc:date>2021-12-11T13:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: Remove extra spaces from string using the field calculator</title>
      <link>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274137#M21206</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Create a function in the pre-logic script code block e.g.: &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def trim(fieldvalue):
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldvalue=' '.join(fieldvalue.strip().split())
&amp;nbsp;&amp;nbsp;&amp;nbsp; # in case fieldvalue=='', change empty string to space 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # to avoid "Field is not Nullable" error
&amp;nbsp;&amp;nbsp;&amp;nbsp; if not fieldvalue: fieldvalue=' '
&amp;nbsp;&amp;nbsp;&amp;nbsp; return fieldvalue&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]29091[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:23:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-extra-spaces-from-string-using-the-field/m-p/274137#M21206</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2021-12-11T13:23:01Z</dc:date>
    </item>
  </channel>
</rss>

