<?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: Copying only text from a string field to a new field in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336111#M26351</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Are the text and integer values separated by a space?&amp;nbsp; You can most likely use the .split command to do this.&amp;nbsp; However, this will be a little more difficult if any of the river names contain spaces.&amp;nbsp; Are all the integer values the same length (i.e. 100, 220, 354, etc)?&amp;nbsp; It may be best to provide a screen shot of how the field looks in your attribute table.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 19 Jul 2012 09:41:15 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2012-07-19T09:41:15Z</dc:date>
    <item>
      <title>Copying only text from a string field to a new field</title>
      <link>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336110#M26350</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Good day,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I know this is probably a stupid question. I am working with a river data set and the labeling field is a string field containing text (river names) and integer (river codes). I want to copy only the text (river names) to a new field. How can I do this with the field calculator... any help will be appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;P&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jul 2012 09:22:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336110#M26350</guid>
      <dc:creator>PieterSnyders</dc:creator>
      <dc:date>2012-07-19T09:22:35Z</dc:date>
    </item>
    <item>
      <title>Re: Copying only text from a string field to a new field</title>
      <link>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336111#M26351</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Are the text and integer values separated by a space?&amp;nbsp; You can most likely use the .split command to do this.&amp;nbsp; However, this will be a little more difficult if any of the river names contain spaces.&amp;nbsp; Are all the integer values the same length (i.e. 100, 220, 354, etc)?&amp;nbsp; It may be best to provide a screen shot of how the field looks in your attribute table.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jul 2012 09:41:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336111#M26351</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2012-07-19T09:41:15Z</dc:date>
    </item>
    <item>
      <title>Re: Copying only text from a string field to a new field</title>
      <link>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336112#M26352</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have attached two sections of the field&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jul 2012 09:48:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336112#M26352</guid>
      <dc:creator>PieterSnyders</dc:creator>
      <dc:date>2012-07-19T09:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: Copying only text from a string field to a new field</title>
      <link>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336113#M26353</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Some of the river names do have spaces&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jul 2012 09:49:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336113#M26353</guid>
      <dc:creator>PieterSnyders</dc:creator>
      <dc:date>2012-07-19T09:49:13Z</dc:date>
    </item>
    <item>
      <title>Re: Copying only text from a string field to a new field</title>
      <link>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336114#M26354</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here is an example on how you can do this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Codeblock:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def update(field):
&amp;nbsp; if field[0] in str(range(0, 9)) or field[0] == '#':
&amp;nbsp;&amp;nbsp;&amp;nbsp; pass
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return field&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Field=&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;update(!TAG!)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Be sure 'Python' is checked on at the top of the field calculator.&amp;nbsp; Here is a screen shot.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]16236[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:55:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336114#M26354</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T15:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: Copying only text from a string field to a new field</title>
      <link>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336115#M26355</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you, that worked partially, this is what is left:&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jul 2012 10:31:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336115#M26355</guid>
      <dc:creator>PieterSnyders</dc:creator>
      <dc:date>2012-07-19T10:31:18Z</dc:date>
    </item>
    <item>
      <title>Re: Copying only text from a string field to a new field</title>
      <link>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336116#M26356</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Use a&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://en.wikipedia.org/wiki/Regular_expression" rel="nofollow noopener noreferrer" target="_blank"&gt;Regular Expression&lt;/A&gt;&lt;SPAN&gt; to match names with letters to make a selection, then just do a copy on selected records. Regular expressions are supported in Python and are a very powerful text manipulation tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe we could assume that no names start with a digit, so you could reverse the search to look for any integer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But if you didn't, an expression&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG&gt;re.match('[A-Za-z ]+',inField) &lt;/STRONG&gt;&lt;SPAN&gt; would allow any combination of letters and spaces&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# pseudocode (not run) for interactive Python window
# NOT field calculator (keep that for modelbuilder....)
import arcpy
import re
arcpy.env.workspace = "your_gdb_path"
cur = arcpy.UpdateCursor("table1")
for row in cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp; m = re.match('[0-9]+',row.inField) # matches any value beginning with integer string of digits
&amp;nbsp;&amp;nbsp;&amp;nbsp; if not m : # ie not nothing found
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.nameCopy = m.string
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cur.updateRow(row) # must not forget this or doesn't write to file
del cur # close cursor

# nameCopy is target field, inField is source field
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:55:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336116#M26356</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2021-12-11T15:55:47Z</dc:date>
    </item>
    <item>
      <title>Re: Copying only text from a string field to a new field</title>
      <link>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336117#M26357</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Use a&amp;nbsp; &lt;A href="http://en.wikipedia.org/wiki/Regular_expression" rel="nofollow noopener noreferrer" target="_blank"&gt;Regular Expression&lt;/A&gt; to match names with letters to make a selection, then just do a copy on selected records. Regular expressions are supported in Python and are a very powerful text manipulation tool.&lt;BR /&gt;&lt;BR /&gt;Maybe we could assume that no names start with a digit, so you could reverse the search to look for any integer&lt;BR /&gt;But if you didn't, an expression&amp;nbsp; &lt;STRONG&gt;re.match('[A-Za-z ]+',inField) &lt;/STRONG&gt; would allow any combination of letters and spaces&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# pseudocode (not run) for interactive Python window
# NOT field calculator (keep that for modelbuilder....)
import arcpy
import re
arcpy.env.workspace = "your_gdb_path"
cur = arcpy.UpdateCursor("table1")
for row in cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp; m = re.match('[0-9]+',row.inField) # matches any value beginning with integer string of digits
&amp;nbsp;&amp;nbsp;&amp;nbsp; if not m : # ie not nothing found
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.nameCopy = m.string
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cur.updateRow(row) # must not forget this or doesn't write to file
del cur # close cursor

# nameCopy is target field, inField is source field
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Where should this code go... I am very new to this and quite confused lol&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:55:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336117#M26357</guid>
      <dc:creator>PieterSnyders</dc:creator>
      <dc:date>2021-12-11T15:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: Copying only text from a string field to a new field</title>
      <link>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336118#M26358</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thank you, that worked partially, this is what is left:&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can you send a screen shot of what you entered in the Field Calculator.&amp;nbsp; It looks like the code did the opposite of what you are looking to accomplish.&amp;nbsp; It calculated all the text values that begin with a number and '#' sign, and not the values that begin with a character.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jul 2012 10:49:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336118#M26358</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2012-07-19T10:49:32Z</dc:date>
    </item>
    <item>
      <title>Re: Copying only text from a string field to a new field</title>
      <link>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336119#M26359</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Can you send a screen shot of what you entered in the Field Calculator.&amp;nbsp; It looks like the code did the opposite of what you are looking to accomplish.&amp;nbsp; It calculated all the text values that begin with a number and '#' sign, and not the values that begin with a character.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the snapshot&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jul 2012 10:58:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336119#M26359</guid>
      <dc:creator>PieterSnyders</dc:creator>
      <dc:date>2012-07-19T10:58:27Z</dc:date>
    </item>
    <item>
      <title>Re: Copying only text from a string field to a new field</title>
      <link>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336120#M26360</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You will want to specify the field that has the current values in the update() function.&amp;nbsp; So, change:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt; update(!Label_Field!)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;to: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;update(!TAG!)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This will calculate the values, that begin with a character, from the TAG field to the LABEL_FIELD.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jul 2012 11:12:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336120#M26360</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2012-07-19T11:12:11Z</dc:date>
    </item>
    <item>
      <title>Re: Copying only text from a string field to a new field</title>
      <link>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336121#M26361</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Success! Thank you! Now I will just have to figure out exactly how this works lol&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jul 2012 11:23:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336121#M26361</guid>
      <dc:creator>PieterSnyders</dc:creator>
      <dc:date>2012-07-19T11:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: Copying only text from a string field to a new field</title>
      <link>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336122#M26362</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Funny enough two numerical values remained: 92 and 9390553&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jul 2012 11:29:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336122#M26362</guid>
      <dc:creator>PieterSnyders</dc:creator>
      <dc:date>2012-07-19T11:29:06Z</dc:date>
    </item>
    <item>
      <title>Re: Copying only text from a string field to a new field</title>
      <link>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336123#M26363</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That was my mistake, the code should have been:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def update(field):
&amp;nbsp; if field[0] in str(range(0, 10)) or field[0] == '#':
&amp;nbsp;&amp;nbsp;&amp;nbsp; pass
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return field&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What this code is doing is checking the first character of each value.&amp;nbsp; If the first character is a number within the range of 0 - 10, or if the character is a '#' sign it will pass this row.&amp;nbsp; If the character is a letter, it will update the row in the new field with that value.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:55:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336123#M26363</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T15:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: Copying only text from a string field to a new field</title>
      <link>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336124#M26364</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for the explanation, will speed up my work! Really need to learn more of this very handy!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jul 2012 11:39:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copying-only-text-from-a-string-field-to-a-new/m-p/336124#M26364</guid>
      <dc:creator>PieterSnyders</dc:creator>
      <dc:date>2012-07-19T11:39:06Z</dc:date>
    </item>
  </channel>
</rss>

