<?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: Parse/Trim function in field calculator in Data Management Questions</title>
    <link>https://community.esri.com/t5/data-management-questions/parse-trim-function-in-field-calculator/m-p/92720#M5485</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;My indents did not show up with the copy/paste.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 15 Jan 2013 00:25:23 GMT</pubDate>
    <dc:creator>KristinAldous</dc:creator>
    <dc:date>2013-01-15T00:25:23Z</dc:date>
    <item>
      <title>Parse/Trim function in field calculator</title>
      <link>https://community.esri.com/t5/data-management-questions/parse-trim-function-in-field-calculator/m-p/92717#M5482</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 am new to python and coding in ArcGIS.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am looking to remove a character at a specfic location in a string with the field calculator.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;e.g. 1-01 needs to be 1-1&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In this case it is always a 0 at the third location.&amp;nbsp; I know there are fairly simple parse and trim functions for this purpose but I havent been able to find a summary of these functions to figure it out (anyone know any help pages on these?)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Kristin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Jan 2013 05:33:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/parse-trim-function-in-field-calculator/m-p/92717#M5482</guid>
      <dc:creator>KristinAldous</dc:creator>
      <dc:date>2013-01-14T05:33:17Z</dc:date>
    </item>
    <item>
      <title>Re: Parse/Trim function in field calculator</title>
      <link>https://community.esri.com/t5/data-management-questions/parse-trim-function-in-field-calculator/m-p/92718#M5483</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Good question, see:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Calculate Field examples &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Geodata » Data types » Tables&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//005s0000002m000000"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//005s0000002m000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...particularly the heading &lt;/SPAN&gt;&lt;STRONG&gt;Python built-in functions&lt;/STRONG&gt;&lt;SPAN&gt;, under which there's a link to the Python site.&amp;nbsp; For your question on strings, you'll need to refer to the section &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;3.1.2. Strings&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So if your string formatting given in your example is constant throughout your table's field, then (using the Python parser in the field calculator), I believe you can do this (test it, replacing &amp;lt;your fieldname&amp;gt; with the applicable field name from your table):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;!&amp;lt;your fieldname&amp;gt;![0:2] + !&amp;lt;your fieldname&amp;gt;![-1:]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Jan 2013 14:06:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/parse-trim-function-in-field-calculator/m-p/92718#M5483</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-01-14T14:06:54Z</dc:date>
    </item>
    <item>
      <title>Re: Parse/Trim function in field calculator</title>
      <link>https://community.esri.com/t5/data-management-questions/parse-trim-function-in-field-calculator/m-p/92719#M5484</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the link.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I wasn't able to get the code you suggested to work though.&amp;nbsp; It doesnt return errors, just simply does not update the text.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My problem is a little more complex as well - only some entries have a zero in the third position.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;e.g. 1-01 should be 1-1 however 1-10 needs to remain 1-10.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried to write a Python code block in the field calculator to attempt to return the characters at 1,2, and 4, only if there is a 0 at character 3, however I have been having trouble getting the syntax for using field names and understanding when to use [ ], ! or ( ). (This code returns parse error at line 2).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Expression: RemoveZero( !M_U_!)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Code: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;def RemoveZero( M_U_):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; if left ([ M_U_], 3) = 0:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return left ([ M_U_], 1,2) + Mid ([ M_U_], 4, 1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any suggestions are much appreciated!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Jan 2013 00:23:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/parse-trim-function-in-field-calculator/m-p/92719#M5484</guid>
      <dc:creator>KristinAldous</dc:creator>
      <dc:date>2013-01-15T00:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: Parse/Trim function in field calculator</title>
      <link>https://community.esri.com/t5/data-management-questions/parse-trim-function-in-field-calculator/m-p/92720#M5485</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;My indents did not show up with the copy/paste.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Jan 2013 00:25:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/parse-trim-function-in-field-calculator/m-p/92720#M5485</guid>
      <dc:creator>KristinAldous</dc:creator>
      <dc:date>2013-01-15T00:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: Parse/Trim function in field calculator</title>
      <link>https://community.esri.com/t5/data-management-questions/parse-trim-function-in-field-calculator/m-p/92721#M5486</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Okay, to paste code here you need the code tags, place  &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;after&lt;/SPAN&gt;&lt;SPAN&gt; your code and &lt;/SPAN&gt;&lt;PRE class="plain" name="code"&gt; before your code - I reversed them here so you could see what I mean (had I not done that, the part of my sentence in-between the tags would have been formatted as a block of code.&amp;nbsp; You originally expressed interest in the Python parser, so the below corrected code should work, using the expression, RemoveZero(!M_U_!): &lt;PRE&gt; def RemoveZero(txtStr): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; txtLst = txtStr.split('-') &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; txtStr = txtLst[0] + '-' + str(int(txtLst[1])) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return txtStr&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Don't forget to use the Python parser (check that box on).&amp;nbsp; Looks like you were mixing VBScript and Python conventions.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;As a brief explanation, the exclamation marks (!) are a way to pass in field values in Python (the brackets, [], are used in VBScript).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The function is called by the expression, RemoveZero(!M_U_!), where M_U_ is the denoted field.&amp;nbsp; In the line of the code block declaring the function definition, def RemoveZero(txtStr), the 'txtStr' variable is a 'dummy' substitution for the value found in M_U_.&amp;nbsp; In other words the value is passed from M_U_ to txtStr where it is operated on in the function and returned as txtStr...it could have been returned as something else, but txtStr was convenient.&amp;nbsp; As long as the correct data type (and length, etc.) is returned, the field you are calculating will accept the value.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that helps.&amp;nbsp; By the way, the last expression given you, !&amp;lt;your fieldname&amp;gt;![0:2] + !&amp;lt;your fieldname&amp;gt;![-1:], was for a calculation &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;without&lt;/SPAN&gt;&lt;SPAN&gt; the code block, also used with the Python parser.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If all's well, please mark this post as 'answered'...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Jan 2013 03:55:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/parse-trim-function-in-field-calculator/m-p/92721#M5486</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-01-15T03:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: Parse/Trim function in field calculator</title>
      <link>https://community.esri.com/t5/data-management-questions/parse-trim-function-in-field-calculator/m-p/92722#M5487</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks so much for the python help!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was able to get the code working using the array rather than the left, mid functions.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's the code I used:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Expression:RemoveZero(!M_U_!):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def RemoveZero(txtstr):
&amp;nbsp; txtList = list(txtstr)
&amp;nbsp; if (txtList[2] == '0'):
&amp;nbsp;&amp;nbsp;&amp;nbsp; txtList2 = txtList[0], txtList[1], txtList[3]
&amp;nbsp;&amp;nbsp;&amp;nbsp; txtstr = ''.join(txtList2)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return txtstr
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return txtstr
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And of course I was using the wrong parser for the !&amp;lt;your fieldname&amp;gt;![0:2] + !&amp;lt;your fieldname&amp;gt;![-1:] expression.&amp;nbsp; It works fine and I'm sure will come in handy.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Kristin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 23:32:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/parse-trim-function-in-field-calculator/m-p/92722#M5487</guid>
      <dc:creator>KristinAldous</dc:creator>
      <dc:date>2021-12-10T23:32:52Z</dc:date>
    </item>
  </channel>
</rss>

