<?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 Splitting a string in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/removing-numeric-characters-from-alphanumeric/m-p/369713#M29230</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I want to extract the columns and rows into their own fields such that "23-999" becomes "23" and "999" using "-" as a delimiter. The problem is that the lengths are variable, eg the field can contain values like "1-2", "351-7", "81-253" which makes substring, trim, left and right commands tricky.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I suggest doing the Calculate Field using Python syntax instead of VBScript (the default for Calculate Field). The split function makes this easier:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
!Col_Row!.split("-")[0]
!Col_Row!.split("-")[1]
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 17:08:37 GMT</pubDate>
    <dc:creator>curtvprice</dc:creator>
    <dc:date>2021-12-11T17:08:37Z</dc:date>
    <item>
      <title>removing numeric characters from alphanumeric string in field calculator ArcMap 10</title>
      <link>https://community.esri.com/t5/python-questions/removing-numeric-characters-from-alphanumeric/m-p/369709#M29226</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a field containing alphanumeric values in the following format:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A-AA00&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sometimes they are also&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A-AAA0&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I need a python script I can put in the field calculator in ArcMap 10 that will at least remove the numeric characters, and retrain the alphabetical ones and the hyphen. So that, for example, this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A-AA0&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;becomes this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A-AA&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I also want to replace the numeric chars with numeric chars from another field. &lt;/SPAN&gt;&lt;A href="http://gis.stackexchange.com/questions/10749/find-and-replace-expression-needed-in-field-calculator-arcgis-10/18701#18701"&gt;This Stack Exchange&lt;/A&gt;&lt;SPAN&gt; entry addresses this issue, but the string has a space before the number and this can be used for splitting and indexing... my strings are not so handily constructed.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Jan 2012 05:10:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/removing-numeric-characters-from-alphanumeric/m-p/369709#M29226</guid>
      <dc:creator>wilfredwaters</dc:creator>
      <dc:date>2012-01-11T05:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: removing numeric characters from alphanumeric string in field calculator ArcMap 1</title>
      <link>https://community.esri.com/t5/python-questions/removing-numeric-characters-from-alphanumeric/m-p/369710#M29227</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try something like this in the field calculator.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Expression:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;ReplaceLastNumber(!textfield!, !numberfield!)
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Code block:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import re
def ReplaceLastNumber(text_value, number_value):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; numbers = re.findall("\d+", text_value)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if numbers:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; last_number = numbers[-1]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; last_number_index = text_value.rfind(last_number)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return text_value[:last_number_index] + str(number_value) + text_value[last_number_index + len(last_number):]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return text_value&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:08:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/removing-numeric-characters-from-alphanumeric/m-p/369710#M29227</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2021-12-11T17:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: modifying  string fields using regular expressions (with Calculate Field)</title>
      <link>https://community.esri.com/t5/python-questions/removing-numeric-characters-from-alphanumeric/m-p/369711#M29228</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Try something like this in the field calculator.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Expression:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;ReplaceLastNumber(!textfield!, !numberfield!)
&lt;/PRE&gt;&lt;BR /&gt;Code block:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import re
def ReplaceLastNumber(text_value, number_value):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; numbers = re.findall("\d+", text_value)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if numbers:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; last_number = numbers[-1]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; last_number_index = text_value.rfind(last_number)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return text_value[:last_number_index] + str(number_value) + text_value[last_number_index + len(last_number):]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return text_value&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks Jason! The &lt;/SPAN&gt;&lt;A href="http://docs.python.org/library/re.html" rel="nofollow noopener noreferrer" target="_blank"&gt;re module&lt;/A&gt;&lt;SPAN&gt; is very useful but rough going when&amp;nbsp; you don't use it often, so the code snippet is very much appreciated. (posting with a new subject line so others can find it!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:08:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/removing-numeric-characters-from-alphanumeric/m-p/369711#M29228</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T17:08:34Z</dc:date>
    </item>
    <item>
      <title>Re: removing numeric characters from alphanumeric string in field calculator ArcMap 1</title>
      <link>https://community.esri.com/t5/python-questions/removing-numeric-characters-from-alphanumeric/m-p/369712#M29229</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a somewhat related question, though it pertains to Arcmap 9.3.1.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a field [Col_Row] that gives the column and row of a shapefile grid in the format of 23-999.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to extract the columns and rows into their own fields such that "23-999" becomes "23" and "999" using "-" as a delimiter. The problem is that the lengths are variable, eg the field can contain values like "1-2", "351-7", "81-253" which makes substring, trim, left and right commands tricky.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've tried using substring as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;substring([Col_Row],1,instr([Col_Row],'-')-1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But I get a VBA error...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be much appreciated. Such a simple task, and yet I've already spent hours trying to do it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jan 2012 19:02:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/removing-numeric-characters-from-alphanumeric/m-p/369712#M29229</guid>
      <dc:creator>EricaBickford</dc:creator>
      <dc:date>2012-01-17T19:02:55Z</dc:date>
    </item>
    <item>
      <title>Splitting a string</title>
      <link>https://community.esri.com/t5/python-questions/removing-numeric-characters-from-alphanumeric/m-p/369713#M29230</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I want to extract the columns and rows into their own fields such that "23-999" becomes "23" and "999" using "-" as a delimiter. The problem is that the lengths are variable, eg the field can contain values like "1-2", "351-7", "81-253" which makes substring, trim, left and right commands tricky.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I suggest doing the Calculate Field using Python syntax instead of VBScript (the default for Calculate Field). The split function makes this easier:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
!Col_Row!.split("-")[0]
!Col_Row!.split("-")[1]
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:08:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/removing-numeric-characters-from-alphanumeric/m-p/369713#M29230</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T17:08:37Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a string</title>
      <link>https://community.esri.com/t5/python-questions/removing-numeric-characters-from-alphanumeric/m-p/369714#M29231</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks curtvprice,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But I didn't think it was possible to use python with Arc 9.3.1....is it?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jan 2012 17:39:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/removing-numeric-characters-from-alphanumeric/m-p/369714#M29231</guid>
      <dc:creator>EricaBickford</dc:creator>
      <dc:date>2012-01-25T17:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a string</title>
      <link>https://community.esri.com/t5/python-questions/removing-numeric-characters-from-alphanumeric/m-p/369715#M29232</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;But I didn't think it was possible to use python with Arc 9.3.1....is it?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sure can, see the &lt;/SPAN&gt;&lt;A href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?id=1626&amp;amp;pid=1622&amp;amp;topicname=Calculate_Field_(Data_Management)" rel="nofollow noopener noreferrer" target="_blank"&gt;Arc 9.3 doc for Calculate Field&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The VBScript syntax you're looking for is this. Note the Mid() function and the double-quote. &lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Mid([Row_Col],1,InStr([Row_Col],"-")-1)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's my bookmarked VBScript reference:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://www.w3schools.com/vbscript/vbscript_ref_functions.asp" rel="nofollow noopener noreferrer" target="_blank"&gt;http://www.w3schools.com/vbscript/vbscript_ref_functions.asp&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:08:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/removing-numeric-characters-from-alphanumeric/m-p/369715#M29232</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T17:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a string</title>
      <link>https://community.esri.com/t5/python-questions/removing-numeric-characters-from-alphanumeric/m-p/369716#M29233</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ah, mid! I've done this before, I just couldn't remember which function I'd used...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I looked into the python-field calculator documentation you linked - as using python would really be much better - but my field calculator wouldn't accept the python code. I'll have to look into whether some kind of python update or plugin is required. It looks like Arc 10 allows you to indicate that you are using python...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the meantime, thanks very much for the VB help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jan 2012 18:54:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/removing-numeric-characters-from-alphanumeric/m-p/369716#M29233</guid>
      <dc:creator>EricaBickford</dc:creator>
      <dc:date>2012-01-25T18:54:11Z</dc:date>
    </item>
  </channel>
</rss>

