<?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: Convert string to Int. and parse the return. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/convert-string-to-int-and-parse-the-return/m-p/21809#M1697</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This sounds like exactly what I want to do..  I will try it in the morning when I return to work.  Thank you..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 18 Sep 2015 00:07:15 GMT</pubDate>
    <dc:creator>TerryGustafson</dc:creator>
    <dc:date>2015-09-18T00:07:15Z</dc:date>
    <item>
      <title>Convert string to Int. and parse the return.</title>
      <link>https://community.esri.com/t5/python-questions/convert-string-to-int-and-parse-the-return/m-p/21803#M1691</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm very new to Python.&amp;nbsp; I want to use python to convert a string to and integer and return only a portion of the string.&amp;nbsp; I have the following string type C000004N_37.&amp;nbsp; I want to convert to int and return just the 37 of the string.&amp;nbsp; C000004N_37 is a route with the following meaning. C standards for Corridor. the 6 numbers are the route number.&amp;nbsp; The N is the roadbed direction so it can be "N", "S", "E" or "W".&amp;nbsp; the underscore just creates a space and the 37 denotes the Reference Marker.&amp;nbsp; The reference marker value could be anything from 1-670.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Sep 2015 19:59:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-string-to-int-and-parse-the-return/m-p/21803#M1691</guid>
      <dc:creator>TerryGustafson</dc:creator>
      <dc:date>2015-09-17T19:59:32Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string to Int. and parse the return.</title>
      <link>https://community.esri.com/t5/python-questions/convert-string-to-int-and-parse-the-return/m-p/21804#M1692</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Terry,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is an example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;val = 'C000004N_37'
val = int(val.split("_")[-1])
print val&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:53:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-string-to-int-and-parse-the-return/m-p/21804#M1692</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-10T20:53:34Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string to Int. and parse the return.</title>
      <link>https://community.esri.com/t5/python-questions/convert-string-to-int-and-parse-the-return/m-p/21805#M1693</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If the string is always separated by an underscore, you could use the string "split()" method: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;int('C000004N_37'.split('_')[1])&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This splits the string into a list with two elements at the underscore, selects the 2nd element (python lists are numbered starting from 0) and converts that to integer.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Sep 2015 20:14:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-string-to-int-and-parse-the-return/m-p/21805#M1693</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2015-09-17T20:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string to Int. and parse the return.</title>
      <link>https://community.esri.com/t5/python-questions/convert-string-to-int-and-parse-the-return/m-p/21806#M1694</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This works for that specific Corridor but I have 12000 records I need to run this on..  can I put some wild card in for the ‘C000004N_37’ that would work with any corridor route?  The C will always be constant.  Followed by 6 numbers.  Then a letter of either N,S,E or W.  then the underscore and a Reference Marker number of 1-670&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Sep 2015 20:40:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-string-to-int-and-parse-the-return/m-p/21806#M1694</guid>
      <dc:creator>TerryGustafson</dc:creator>
      <dc:date>2015-09-17T20:40:50Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string to Int. and parse the return.</title>
      <link>https://community.esri.com/t5/python-questions/convert-string-to-int-and-parse-the-return/m-p/21807#M1695</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Strings are a &lt;A href="https://docs.python.org/2/library/stdtypes.html#sequence-types-str-unicode-list-tuple-bytearray-buffer-xrange" rel="nofollow noopener noreferrer" target="_blank"&gt;Sequence Type &lt;/A&gt;in Python, which means they support indexing and slicing.&amp;nbsp; Since you have a standard number of characters to the left and variable number to the right of the underscore, you can just slice off the right-hand side of the string.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;val = 'C000004N_37'
val = int(val[9:])&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:53:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-string-to-int-and-parse-the-return/m-p/21807#M1695</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-10T20:53:37Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string to Int. and parse the return.</title>
      <link>https://community.esri.com/t5/python-questions/convert-string-to-int-and-parse-the-return/m-p/21808#M1696</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you need to do this just once, the simplest way is in the field calculator:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Open the table, right-click on the heading of the field you want to store your result in, and select "Field Calculator"&lt;/LI&gt;&lt;LI&gt;Select "Python" for the parser.&lt;/LI&gt;&lt;LI&gt;In the expression window,, enter the expression that Luke gave you above, but replace the string "C000004N_37" with your input field name, surrounded by "!" signs.&amp;nbsp; For my test, the expression looked like this:&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int(!RouteID!.split("_")[1])&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you need to do this in a Python script, on the other hand, you'll need to use an Update Cursor to step through the records, read the initial value, parse it using the "split" method, then write the results back to your output field.&amp;nbsp; There are some good examples in the ArcPy help, under "Data Access Module".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Sep 2015 23:21:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-string-to-int-and-parse-the-return/m-p/21808#M1696</guid>
      <dc:creator>EarlSarow</dc:creator>
      <dc:date>2015-09-17T23:21:02Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string to Int. and parse the return.</title>
      <link>https://community.esri.com/t5/python-questions/convert-string-to-int-and-parse-the-return/m-p/21809#M1697</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This sounds like exactly what I want to do..  I will try it in the morning when I return to work.  Thank you..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Sep 2015 00:07:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-string-to-int-and-parse-the-return/m-p/21809#M1697</guid>
      <dc:creator>TerryGustafson</dc:creator>
      <dc:date>2015-09-18T00:07:15Z</dc:date>
    </item>
  </channel>
</rss>

