<?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: VB Script to replace strings in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/vb-script-to-replace-strings/m-p/237552#M18464</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think Richard is recommending the Right method as the information you want to retain is all on the right and the excess to be removed is on the left.&amp;nbsp; Therefore you can use Right, specifying 10 characters, and everything more than 10 characters to left will be removed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Chris Donohue, GISP&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 07 Jul 2015 18:21:13 GMT</pubDate>
    <dc:creator>ChrisDonohue__GISP</dc:creator>
    <dc:date>2015-07-07T18:21:13Z</dc:date>
    <item>
      <title>VB Script to replace strings</title>
      <link>https://community.esri.com/t5/python-questions/vb-script-to-replace-strings/m-p/237548#M18460</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello everyone! Very new to the GIS industry, but I'm hoping to learn more down the line. Forgive me if this is a very basic question.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Right now I'm having trouble doing something I think should be very simple. I'm just to replace a string in a field with another string using the Field Calculator. However, every time I run the calculation absolutely nothing appears to happen to the records within the field in question. I am working with ~4,000 records and some of them have unnecessary leading zeroes in them. Normally I would run a calculation that would remove all the leading zeroes but certain records need it while others don't. As a result, I thought it would be easier to just entirely replace the ones that have the unnecessary leading zeroes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is what I'm entering into the Field Calculator &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATE_TEXT&lt;/P&gt;&lt;P&gt;= Replace([DATE_TEXT], "011/12/2014","11/12/2014")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The numbers are both set to strings and I have made sure to check the VB Script parser. I've also tried it using the Python parser:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATE_TEXT&lt;/P&gt;&lt;P&gt;=!DATE_TEXT!.replace("011/12/2014","11/12/2014")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But with no luck. What am I doing wrong? Is it the settings? I'm working with a standalone shape file in Arc 10.3.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 17:57:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/vb-script-to-replace-strings/m-p/237548#M18460</guid>
      <dc:creator>DeidreA</dc:creator>
      <dc:date>2015-07-07T17:57:31Z</dc:date>
    </item>
    <item>
      <title>Re: VB Script to replace strings</title>
      <link>https://community.esri.com/t5/python-questions/vb-script-to-replace-strings/m-p/237549#M18461</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The expression looks correct, but it will only affect a record with the exact value of "0&lt;SPAN style="color: #000000; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;11/12/2014".&amp;nbsp; I would instead select all records that have the leading zero you don't want and then remove it using the Right() method.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;For a File Geodatabase feature class the SQL expression for a Select By Attribute query to select records with an extra leading zero in the month should be:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;DATE_TEXT Like '0__/%'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Assuming that selects all records with an extra zero, use this VB Script expression to calculate the field to remove the first character in the string:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Right([DATE_TEXT], len([DATE_TEXT) - 1))&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 18:06:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/vb-script-to-replace-strings/m-p/237549#M18461</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2015-07-07T18:06:04Z</dc:date>
    </item>
    <item>
      <title>Re: VB Script to replace strings</title>
      <link>https://community.esri.com/t5/python-questions/vb-script-to-replace-strings/m-p/237550#M18462</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your prompt reply!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problem is that what I'm doing doesn't even affect the one type of record I'm looking at. That's why I'm so stumped.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;About your solution - I'm a little confused. Why would I use the right method? The leading zeroes are to the left of the string. Wouldn't it just be Left([DATE_TEXT], len([DATE_TEXT] - 1)?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edit: Also, my file isn't stored in a geodatabase. It's a standalone feature class. Would that SQL expression still apply?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 18:13:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/vb-script-to-replace-strings/m-p/237550#M18462</guid>
      <dc:creator>DeidreA</dc:creator>
      <dc:date>2015-07-07T18:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: VB Script to replace strings</title>
      <link>https://community.esri.com/t5/python-questions/vb-script-to-replace-strings/m-p/237551#M18463</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 = "011/12/2014"
&amp;gt;&amp;gt;&amp;gt; a
'011/12/2014'
&amp;gt;&amp;gt;&amp;gt; b = a.replace("011/12/2014","11/12/2014")
&amp;gt;&amp;gt;&amp;gt; b
'11/12/2014'
&amp;gt;&amp;gt;&amp;gt; a.replace("011/12/2014","11/12/2014")
'11/12/2014'
&amp;gt;&amp;gt;&amp;gt; a
'011/12/2014'
&amp;gt;&amp;gt;&amp;gt; # hmmmm thought I changed me????
a = a[1:]
&amp;gt;&amp;gt;&amp;gt; a
'11/12/2014'&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have you tried to add a new field and send the calculation there, since overwriting itself doesn't appear to be the way to go. EDIT slice instead&lt;/P&gt;&lt;P&gt;​&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:58:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/vb-script-to-replace-strings/m-p/237551#M18463</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T11:58:08Z</dc:date>
    </item>
    <item>
      <title>Re: VB Script to replace strings</title>
      <link>https://community.esri.com/t5/python-questions/vb-script-to-replace-strings/m-p/237552#M18464</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think Richard is recommending the Right method as the information you want to retain is all on the right and the excess to be removed is on the left.&amp;nbsp; Therefore you can use Right, specifying 10 characters, and everything more than 10 characters to left will be removed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Chris Donohue, GISP&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 18:21:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/vb-script-to-replace-strings/m-p/237552#M18464</guid>
      <dc:creator>ChrisDonohue__GISP</dc:creator>
      <dc:date>2015-07-07T18:21:13Z</dc:date>
    </item>
    <item>
      <title>Re: VB Script to replace strings</title>
      <link>https://community.esri.com/t5/python-questions/vb-script-to-replace-strings/m-p/237553#M18465</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You need to use Right, because you are keeping all of the string on the right minus one character, which would elinminate the left most character (i.e., the leading zero).&amp;nbsp; Using Left would get rid of the last character in the string (i.e., the 4 of 2014), not the first character in the string.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The SQL works for Shapefiles also.&amp;nbsp; If the SQL doesn't work copy and paste an actual value from the field in to a post.&amp;nbsp; You should also paste the DATE_TEXT actual value into your original calculation.&amp;nbsp; Replace only works if every character in the second argument string is found in first argument string.&amp;nbsp; Exact spelling is required.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 18:22:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/vb-script-to-replace-strings/m-p/237553#M18465</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2015-07-07T18:22:54Z</dc:date>
    </item>
    <item>
      <title>Re: VB Script to replace strings</title>
      <link>https://community.esri.com/t5/python-questions/vb-script-to-replace-strings/m-p/237554#M18466</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hmmm I think you can replace in place, and similar in the field calculator...&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 = "011/12/2014"
&amp;gt;&amp;gt;&amp;gt; a
'011/12/2014'
&amp;gt;&amp;gt;&amp;gt; a = a.replace("011/12/2014","11/12/2014")
&amp;gt;&amp;gt;&amp;gt; a
'11/12/2014'&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:58:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/vb-script-to-replace-strings/m-p/237554#M18466</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T11:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: VB Script to replace strings</title>
      <link>https://community.esri.com/t5/python-questions/vb-script-to-replace-strings/m-p/237555#M18467</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;yes.... as long as you reassign a to itself as in your case, but look at mine...that was why I was wondering about the field name.&amp;nbsp; Anyway slicing with reassignment as in my edits also works...without reassignment you just get a view not a copy&lt;/P&gt;&lt;P&gt;​&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 18:34:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/vb-script-to-replace-strings/m-p/237555#M18467</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-07-07T18:34:29Z</dc:date>
    </item>
    <item>
      <title>Re: VB Script to replace strings</title>
      <link>https://community.esri.com/t5/python-questions/vb-script-to-replace-strings/m-p/237556#M18468</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The SQL expression worked out! Thank you! However, for some reason, I still can not get my field calculator to give me the results I would like. It keeps tell me that there was a failure during processing. The Geoprocessing Results window told me it was expecting an extra parenthesis, but I entered:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Right([DATE_TEXT], len([DATE_TEXT] - 1)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I ended up using the Python parser and went with:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;!DATE_TEXT!.lstrip("0")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It did what I wanted it to do at any rate. Thank you for your help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 18:45:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/vb-script-to-replace-strings/m-p/237556#M18468</guid>
      <dc:creator>DeidreA</dc:creator>
      <dc:date>2015-07-07T18:45:15Z</dc:date>
    </item>
    <item>
      <title>Re: VB Script to replace strings</title>
      <link>https://community.esri.com/t5/python-questions/vb-script-to-replace-strings/m-p/237557#M18469</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you count the number of opening (2) and closing (1) parentheses in your RIGHT statement, they are different. They should always match.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14362947711281083 jive_text_macro" data-renderedposition="50_8_912_16" jivemacro_uid="_14362947711281083"&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Right([DATE_TEXT], len([DATE_TEXT] - 1))​&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 18:47:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/vb-script-to-replace-strings/m-p/237557#M18469</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2015-07-07T18:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: VB Script to replace strings</title>
      <link>https://community.esri.com/t5/python-questions/vb-script-to-replace-strings/m-p/237558#M18470</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The missing parenthesis was an error on my part.&amp;nbsp; The expression should have been:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Right([DATE_TEXT], len([DATE_TEXT] - 1))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Just poor proofreading.&amp;nbsp; I fixed the calculation expression in my original post, since you marked that post as the correct answer.&amp;nbsp; That way the answer will be all correct for anyone else that sees it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Your calculation is just as good, and there are probably several other ways to remove the leading zero once you have the correct selection of records.&amp;nbsp; The bottom line is that the pattern is fixed now.&amp;nbsp; Using replace would have been limited to fixing one date at a time to avoid removing zeros you wanted to keep.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 18:48:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/vb-script-to-replace-strings/m-p/237558#M18470</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2015-07-07T18:48:32Z</dc:date>
    </item>
  </channel>
</rss>

