<?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: Split field on first number in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758576#M58561</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about something like this?&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;s ="POWERS 1C-23HZ"
s2 = "RATTLER4C-34HZ"
for string in (s, s2):
&amp;nbsp;&amp;nbsp;&amp;nbsp; string = string.replace(" ", "")&amp;nbsp; ## Drop spaces (optional)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print string
&amp;nbsp;&amp;nbsp;&amp;nbsp; string_builder = ""
&amp;nbsp;&amp;nbsp;&amp;nbsp; field_vals = None
&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in string:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if i.isdigit():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; field_vals = (
&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; string[:len(string_builder)],&amp;nbsp; ## string before number
&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; string[len(string_builder):]&amp;nbsp; ## string after number
&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; print field_vals
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break
&amp;nbsp;&amp;nbsp;&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;&amp;nbsp;&amp;nbsp; string_builder += i&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not clear on how you want to use field calculator to write to two output fields, so I'll let you clarify your intent or adapt this logic to your specific need. You'll at least need to get rid of the first three lines.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;EDIT:&lt;/STRONG&gt;​ Xander and Darren beat me to it! &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/silly.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 08:10:09 GMT</pubDate>
    <dc:creator>BlakeTerhune</dc:creator>
    <dc:date>2021-12-12T08:10:09Z</dc:date>
    <item>
      <title>Split field on first number</title>
      <link>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758572#M58557</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;EM&gt;Edit (by Xander Bakker): the original question was placed at this thread: &lt;A href="https://community.esri.com/thread/86096"&gt;Extracting an integer from a string field&lt;/A&gt; but I decided to branch it to a new thread.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a similar situation...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For Example:&lt;/P&gt;&lt;P&gt;s ="POWERS 1C-23HZ"&lt;/P&gt;&lt;P&gt;and some are like s2 = RATTLER4C-34HZ&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to tell python to find the first number in each field and then split the field at the same location at the first number. so....&lt;/P&gt;&lt;P&gt;Field 1 = RATTLER&lt;/P&gt;&lt;P&gt;Field 2 = 4C-34HZ&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;derived from the string above: s2&lt;/P&gt;&lt;P&gt;I would like to use the field calculator to do this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know you can use this to split on the space:&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_1452810590842956 jive_text_macro" data-renderedposition="407_8_912_16" jivemacro_uid="_1452810590842956"&gt;&lt;P&gt;!field! = s.split(' ')[0]&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did this in the field calculator expression box and it works but only on the strings with a space where I need to break it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help is much appreciated!&lt;/P&gt;&lt;P&gt;Dan A.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Xander Bakker. Post branched to new Thread &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Jan 2016 22:32:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758572#M58557</guid>
      <dc:creator>DanielAmrine</dc:creator>
      <dc:date>2016-01-14T22:32:18Z</dc:date>
    </item>
    <item>
      <title>Re: Split field on first number</title>
      <link>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758573#M58558</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; a = "RATTLER4C-34HZ"&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; b=a.split("-")[0][-2]&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; b&lt;/P&gt;&lt;P&gt;'4'&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Jan 2016 22:39:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758573#M58558</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-01-14T22:39:08Z</dc:date>
    </item>
    <item>
      <title>Re: Split field on first number</title>
      <link>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758574#M58559</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;&amp;gt;&amp;gt;&amp;gt; a = "RATTLER4C-34HZ"
... for i in range(len(a)):
...&amp;nbsp;&amp;nbsp;&amp;nbsp; if a&lt;I&gt;.isdigit():&lt;/I&gt;
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b = [a[:i],a&lt;I&gt;&lt;/I&gt;
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break
... print b
...
['RATTLER', '4C-34HZ']&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:10:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758574#M58559</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-12T08:10:04Z</dc:date>
    </item>
    <item>
      <title>Re: Split field on first number</title>
      <link>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758575#M58560</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Darren is right, his is probably easier to understand...&amp;nbsp; but for continuity&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; a = "RATTLER4C-34HZ"
&amp;gt;&amp;gt;&amp;gt; b = a.split("-")[0][-2]
&amp;gt;&amp;gt;&amp;gt; b
'4'
&amp;gt;&amp;gt;&amp;gt; c="4"+a.split("4",1)[1]
&amp;gt;&amp;gt;&amp;gt; c
'4C-34HZ'&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The number after the "4" is the maximum number of times to split the string, incase you have more than one four, which you do&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:10:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758575#M58560</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-12T08:10:06Z</dc:date>
    </item>
    <item>
      <title>Re: Split field on first number</title>
      <link>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758576#M58561</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about something like this?&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;s ="POWERS 1C-23HZ"
s2 = "RATTLER4C-34HZ"
for string in (s, s2):
&amp;nbsp;&amp;nbsp;&amp;nbsp; string = string.replace(" ", "")&amp;nbsp; ## Drop spaces (optional)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print string
&amp;nbsp;&amp;nbsp;&amp;nbsp; string_builder = ""
&amp;nbsp;&amp;nbsp;&amp;nbsp; field_vals = None
&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in string:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if i.isdigit():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; field_vals = (
&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; string[:len(string_builder)],&amp;nbsp; ## string before number
&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; string[len(string_builder):]&amp;nbsp; ## string after number
&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; print field_vals
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break
&amp;nbsp;&amp;nbsp;&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;&amp;nbsp;&amp;nbsp; string_builder += i&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not clear on how you want to use field calculator to write to two output fields, so I'll let you clarify your intent or adapt this logic to your specific need. You'll at least need to get rid of the first three lines.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;EDIT:&lt;/STRONG&gt;​ Xander and Darren beat me to it! &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/silly.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:10:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758576#M58561</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-12-12T08:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: Split field on first number</title>
      <link>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758577#M58562</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A small addition to the code contributed by Darren. In the example&amp;nbsp; "POWERS 1C-23HZ", your first result will include "POWERS " with the space included. If any space at the beginning or end should be stripped, you can use something like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;a = "POWERS 1C-23HZ"
for i in range(len(a)):
&amp;nbsp; if a&lt;I&gt;.isdigit():&lt;/I&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b = [a.strip() for a in [a[:i],a&lt;I&gt;]&lt;/I&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break
print b

#&amp;nbsp; ['POWERS ', '1C-23HZ']&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to use this in the field calculator and fill two fields with it, you must remember that a Field Calculation can only write to a single field per run. Does than mean that you need two functions to implement&amp;nbsp; what you want? No, not really. You can work with an additional parameter (index) that will extract the value you want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code block could be something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def SplitAtDigit(a, index):
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; found = False
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in range(len(a)):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if a&lt;I&gt;.isdigit():&lt;/I&gt;
&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; b = [a.strip() for a in [a[:i], a&lt;I&gt;]&lt;/I&gt;
&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; found = True
&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; break
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if found:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return b[index]
&amp;nbsp;&amp;nbsp;&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;&amp;nbsp;&amp;nbsp; if index==0:
&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; return a
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return ''
&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return ''&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and you can use these settings:&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/168807_pastedImage_4.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;P&gt;for the first field and:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;SplitAtDigit( !infield!, 1)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;...for the second field. This will result in:&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-2 jive-image" src="https://community.esri.com/legacyfs/online/168808_pastedImage_5.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:10:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758577#M58562</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-12T08:10:12Z</dc:date>
    </item>
    <item>
      <title>Re: Split field on first number</title>
      <link>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758578#M58563</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Xander, good thing you branched it &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/wink.png" /&gt; , poor Phil is probably wondering about the emails he is going to get tomorrow morning on a 3 year old thread &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jan 2016 00:32:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758578#M58563</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-01-15T00:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: Split field on first number</title>
      <link>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758579#M58564</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I apologize &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I should of started a new post but i don't think people would have seen or replied to it as quickly if i had done that!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you all for the ideas. I realize now i will have to do one field at a time if i use the calculator.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you Xander for laying it out like you did....it was very helpful. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jan 2016 14:21:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758579#M58564</guid>
      <dc:creator>DanielAmrine</dc:creator>
      <dc:date>2016-01-15T14:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: Split field on first number</title>
      <link>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758580#M58565</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Xander et al...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the code i entered into the code block:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def SplitAtDigit(a,index):
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; found = False
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in range(len(a)):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if a&lt;I&gt;.isdigit():&lt;/I&gt;
&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; b = [a.strip() for a in [a[:i], a&lt;I&gt;]&lt;/I&gt;
&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; found = True
&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; break
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if found:
&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; return b[index]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if index ==0:
&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; return a
&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; else:
&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; return ' '
&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return ' '&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and then:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;SplitAtDigit( !field!,0)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;unfortunately all it does is copy one field into the new field without splitting the original text string.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i have compared this with what you posted many times and it took me several tries to get the indentation right. i know from the table you posted it worked for you, so I son't understand why it isn't working for me. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All fields i'm using are text fields and i don't see anything else that would keep this from working.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the only other problem i can think of is that some of strings in the original text column have multiple spaces before the first number.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me know if there is anything jumping out at you in this block of code.&lt;/P&gt;&lt;P&gt;Dan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:10:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758580#M58565</guid>
      <dc:creator>DanielAmrine</dc:creator>
      <dc:date>2021-12-12T08:10:14Z</dc:date>
    </item>
    <item>
      <title>Re: Split field on first number</title>
      <link>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758581#M58566</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you post a sample of your data? What is the error you obtain?&lt;/P&gt;&lt;P&gt;You should't have any problems with the indentation, but I can create an expression file that you can load.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jan 2016 15:46:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758581#M58566</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2016-01-15T15:46:35Z</dc:date>
    </item>
    <item>
      <title>Re: Split field on first number</title>
      <link>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758582#M58567</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Find attached the Expression file. In the Field Calculator, click on load:&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/169227_pastedImage_0.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;P&gt;Make sue you switch to the Python parser:&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-2 jive-image" src="https://community.esri.com/legacyfs/online/169228_pastedImage_1.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the part below change the index (0 or 1) according to the field you want to fill:&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-3 jive-image" src="https://community.esri.com/legacyfs/online/169232_pastedImage_2.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jan 2016 15:57:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758582#M58567</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2016-01-15T15:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: Split field on first number</title>
      <link>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758583#M58568</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Xander,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;that worked perfectly!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All except where the text begins with a number such as:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;70 RANCH USX BB 09-99HZ&lt;/P&gt;&lt;P&gt;3D 16N-21HZ&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the script copied the entire string into the field that used the "1" selection...which makes perfect sense. since it found the first number and printed everything past it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are only a few records that start with a number so i can fix it easily.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The difference between mine and the calc file you sent is you had a single " at the end of the final returns. I had used ' '&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm assuming there's a way to tell the script to split it at the first second or third number....by adding a [1]...etc... somewhere in line 6?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now it's more of trying to understand how the script actually works.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jan 2016 16:25:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-field-on-first-number/m-p/758583#M58568</guid>
      <dc:creator>DanielAmrine</dc:creator>
      <dc:date>2016-01-15T16:25:57Z</dc:date>
    </item>
  </channel>
</rss>

