<?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: Field Calc Integers from String in Data Management Questions</title>
    <link>https://community.esri.com/t5/data-management-questions/field-calc-integers-from-string/m-p/1248520#M44358</link>
    <description>&lt;P&gt;Another one&lt;/P&gt;&lt;P&gt;Code Block&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def comp(x):
    numlist = [i for i in x if i.isdigit()]
    if len(numlist)&amp;gt;0:
        return int(''.join(numlist))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expression:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;comp( !NUMBER_STRING! )&lt;/LI-CODE&gt;&lt;P&gt;&lt;A href="https://gis.stackexchange.com/questions/364715/extracting-numbers-from-string-using-field-calculator-of-arcmap" target="_blank"&gt;https://gis.stackexchange.com/questions/364715/extracting-numbers-from-string-using-field-calculator-of-arcmap&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 16 Jan 2023 18:29:16 GMT</pubDate>
    <dc:creator>JayantaPoddar</dc:creator>
    <dc:date>2023-01-16T18:29:16Z</dc:date>
    <item>
      <title>Field Calc Integers from String</title>
      <link>https://community.esri.com/t5/data-management-questions/field-calc-integers-from-string/m-p/1248474#M44353</link>
      <description>&lt;P&gt;I am trying to Field Calc the integers that live in a STRING field for roads. The client only wants the numbers of each road and not any of the text. I have tried :&amp;nbsp;def comp(x):&lt;BR /&gt;return any(i.isdigit() for i in x)&lt;/P&gt;&lt;P&gt;No real results. This finds a number and returns "1" if true and "0" if false. What I need is for the entire number, say 100th Street, would become 100. Any help would be much appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JeremiahMcDonald_0-1673882958334.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/60494i689BD4A46336026E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JeremiahMcDonald_0-1673882958334.png" alt="JeremiahMcDonald_0-1673882958334.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2023 15:29:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/field-calc-integers-from-string/m-p/1248474#M44353</guid>
      <dc:creator>JeremiahMcDonald</dc:creator>
      <dc:date>2023-01-16T15:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calc Integers from String</title>
      <link>https://community.esri.com/t5/data-management-questions/field-calc-integers-from-string/m-p/1248500#M44354</link>
      <description>&lt;P&gt;Several ways to go about it depending on how clean and/or complicated the data are in text fields.&amp;nbsp; You can use&amp;nbsp;&lt;A href="https://docs.python.org/2/library/itertools.html#itertools.takewhile" target="_self"&gt;itertools.takewhile()&lt;/A&gt; or just adopt the pseudo-code from it.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2023 17:01:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/field-calc-integers-from-string/m-p/1248500#M44354</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2023-01-16T17:01:03Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calc Integers from String</title>
      <link>https://community.esri.com/t5/data-management-questions/field-calc-integers-from-string/m-p/1248505#M44355</link>
      <description>&lt;P&gt;can you provide an example with the snippet given?&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2023 17:05:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/field-calc-integers-from-string/m-p/1248505#M44355</guid>
      <dc:creator>JeremiahMcDonald</dc:creator>
      <dc:date>2023-01-16T17:05:41Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calc Integers from String</title>
      <link>https://community.esri.com/t5/data-management-questions/field-calc-integers-from-string/m-p/1248513#M44356</link>
      <description>&lt;P&gt;Using the pseudo-code directly from page I link to:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Codeblock
def takewhile(predicate, iterable):
    for x in iterable:
        if predicate(x):
            yield x
        else:
            break

# Expression 
"".join(takewhile(str.isdigit, !FULLNAME!))&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 16 Jan 2023 17:59:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/field-calc-integers-from-string/m-p/1248513#M44356</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2023-01-16T17:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calc Integers from String</title>
      <link>https://community.esri.com/t5/data-management-questions/field-calc-integers-from-string/m-p/1248514#M44357</link>
      <description>&lt;P&gt;"any" is used to return a boolean, in this case 1/True that there was a number in the field.&lt;/P&gt;&lt;P&gt;If you want the number then&lt;/P&gt;&lt;P&gt;a = '100 some street'&lt;/P&gt;&lt;P&gt;"".join([i for i in a if i.isdigit()])&lt;BR /&gt;'100'&lt;/P&gt;&lt;P&gt;It will continue to return numbers whether they make sense or not like&lt;/P&gt;&lt;P&gt;a = "100 1st ave apt 5"&lt;/P&gt;&lt;P&gt;will return "10015"&lt;/P&gt;&lt;P&gt;which would require some extra work to just get the street address&lt;/P&gt;&lt;LI-CODE lang="python"&gt;a = "100 1st ave apt 5"
# -- getting there
"".join([i for i in a if i.isdigit() or i == " "])
'100 1   5'
# -- split the string and slice the part you want
"".join([i for i in a if i.isdigit() or i == " "]).split(" ")[0]
Out[5]: '100'&lt;/LI-CODE&gt;&lt;P&gt;So examine and modify your use case to avoid such things&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2023 18:00:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/field-calc-integers-from-string/m-p/1248514#M44357</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2023-01-16T18:00:32Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calc Integers from String</title>
      <link>https://community.esri.com/t5/data-management-questions/field-calc-integers-from-string/m-p/1248520#M44358</link>
      <description>&lt;P&gt;Another one&lt;/P&gt;&lt;P&gt;Code Block&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def comp(x):
    numlist = [i for i in x if i.isdigit()]
    if len(numlist)&amp;gt;0:
        return int(''.join(numlist))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expression:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;comp( !NUMBER_STRING! )&lt;/LI-CODE&gt;&lt;P&gt;&lt;A href="https://gis.stackexchange.com/questions/364715/extracting-numbers-from-string-using-field-calculator-of-arcmap" target="_blank"&gt;https://gis.stackexchange.com/questions/364715/extracting-numbers-from-string-using-field-calculator-of-arcmap&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2023 18:29:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/field-calc-integers-from-string/m-p/1248520#M44358</guid>
      <dc:creator>JayantaPoddar</dc:creator>
      <dc:date>2023-01-16T18:29:16Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calc Integers from String</title>
      <link>https://community.esri.com/t5/data-management-questions/field-calc-integers-from-string/m-p/1248554#M44359</link>
      <description>&lt;P&gt;As Dan already mentioned, this general approach will fail when there are other number sequences in the string.&amp;nbsp; For example, an address like "100 South 900 West" will return "100900" with this approach.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2023 21:35:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/field-calc-integers-from-string/m-p/1248554#M44359</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2023-01-16T21:35:54Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calc Integers from String</title>
      <link>https://community.esri.com/t5/data-management-questions/field-calc-integers-from-string/m-p/1248560#M44360</link>
      <description>&lt;P&gt;This is another good use case for my Idea for Esri to&amp;nbsp;&lt;LI-MESSAGE title="Add Python Regular Expression (re) Helpers to Calculate Field Dialog" uid="1247666" url="https://community.esri.com/t5/arcgis-pro-ideas/add-python-regular-expression-re-helpers-to/m-p/1247666#U1247666" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-idea-thread lia-fa-icon lia-fa-idea lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;.&amp;nbsp; Even without the "Helper" functions, you can still use &lt;A href="https://docs.python.org/3/library/re.html" target="_self"&gt;re - Regular expression operations - Python 3 documentation&lt;/A&gt; by just importing the module in the code block:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Codeblock
import re

# Expression
re.match(r"^\s*\d*", !FULLNAME!).group()&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 16 Jan 2023 22:16:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/field-calc-integers-from-string/m-p/1248560#M44360</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2023-01-16T22:16:56Z</dc:date>
    </item>
  </channel>
</rss>

