<?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: How to remove first two and the last two characters from each label in Arcmap? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-remove-first-two-and-the-last-two/m-p/191940#M14777</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For future reference... if you don't know the length of the object to slice... but you know that you want to slice of 2, but be careful, you may not get what you want&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;a &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'PL1607000'&lt;/SPAN&gt;

&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;a&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="string token"&gt;'16070'&lt;/SPAN&gt;‍‍‍‍‍

a &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'PL1'&lt;/SPAN&gt;

&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;a&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="string token"&gt;''&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 09:39:21 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2021-12-11T09:39:21Z</dc:date>
    <item>
      <title>How to remove first two and the last two characters from each label in Arcmap?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-remove-first-two-and-the-last-two/m-p/191937#M14774</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello. My too long labels take up too much space in regard to the small counties polygons.&lt;/P&gt;&lt;P&gt;I want to remove first two and the last two characters from each single label.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently the labels on the map look like this:&lt;/P&gt;&lt;P&gt;PL1607000&lt;/P&gt;&lt;P&gt;PL1816000&lt;/P&gt;&lt;P&gt;LV801200&lt;/P&gt;&lt;P&gt;LT029900&lt;/P&gt;&lt;P&gt;EE700000&lt;/P&gt;&lt;P&gt;etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Because in each single label the first two characters are two-letter country code, and the last two characters always two zeros, to make map more clean I want my labels like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;16070&lt;/P&gt;&lt;P&gt;18160&lt;/P&gt;&lt;P&gt;8012&lt;/P&gt;&lt;P&gt;0299&lt;/P&gt;&lt;P&gt;7000&lt;/P&gt;&lt;P&gt;etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use Maplex Label Engine. My label field is CTYCode, What expression should I type in Label expression dialog box?&lt;/P&gt;&lt;P&gt;Is it possible to also make stacked labels from this labels? I want to the first two characters were at the top, and the rest at the bottom. Like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;16&lt;BR /&gt; 070&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;18&lt;BR /&gt; 160&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;80&lt;BR /&gt; 12&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;02&lt;BR /&gt; 99&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;70&lt;BR /&gt; 00&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;etc.&lt;/P&gt;&lt;P&gt;If you want help me please add here two different expressions. With and without stacking labels, I do not know about programming at all and I would not know how to change the expression &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/wink.png" /&gt;&lt;/P&gt;&lt;P&gt;Greg&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Feb 2018 08:54:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-remove-first-two-and-the-last-two/m-p/191937#M14774</guid>
      <dc:creator>GregoryBrown3</dc:creator>
      <dc:date>2018-02-07T08:54:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove first two and the last two characters from each label in Arcmap?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-remove-first-two-and-the-last-two/m-p/191938#M14775</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Go in to the expression editor, turn on advanced expressions, set the parser to Python, put this as the expression for stacking:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;def FindLabel ( [CTYCode] &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;&amp;nbsp; return "%s\r\n%s" % ([CTYCode][2:4], [CTYCode][4:-2])&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;And without stacking:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;def FindLabel ( [&lt;SPAN style="background-color: #f6f6f6;"&gt;CTYCode&lt;/SPAN&gt;] &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;&amp;nbsp; return ([&lt;SPAN style="background-color: #f6f6f6;"&gt;CTYCode&lt;/SPAN&gt;][2:-2])&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The best things to read up on would be string substitution (the %s stuff), slicing and indexing (the [2:4], [4:-2], etc. stuff) in Python.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Feb 2018 09:30:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-remove-first-two-and-the-last-two/m-p/191938#M14775</guid>
      <dc:creator>PeteCrosier</dc:creator>
      <dc:date>2018-02-07T09:30:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove first two and the last two characters from each label in Arcmap?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-remove-first-two-and-the-last-two/m-p/191939#M14776</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for help! &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/wink.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Feb 2018 14:24:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-remove-first-two-and-the-last-two/m-p/191939#M14776</guid>
      <dc:creator>GregoryBrown3</dc:creator>
      <dc:date>2018-02-07T14:24:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove first two and the last two characters from each label in Arcmap?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-remove-first-two-and-the-last-two/m-p/191940#M14777</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For future reference... if you don't know the length of the object to slice... but you know that you want to slice of 2, but be careful, you may not get what you want&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;a &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'PL1607000'&lt;/SPAN&gt;

&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;a&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="string token"&gt;'16070'&lt;/SPAN&gt;‍‍‍‍‍

a &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'PL1'&lt;/SPAN&gt;

&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;a&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="string token"&gt;''&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:39:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-remove-first-two-and-the-last-two/m-p/191940#M14777</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T09:39:21Z</dc:date>
    </item>
  </channel>
</rss>

