<?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 Indexing into a list without errors in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Indexing-into-a-list-without-errors/m-p/518455#M74449</link>
    <description>&lt;P&gt;Let's say I have a file name that I parse into separate parts like so:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;nameWords = Words(name, "_")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Let's say I want to make a short name out of the first five words of the original name:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;shortName = Concat Items( nameWords[{1, 2, 3, 4, 5}], "_" );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Everything works fine while I'm getting names in the format that I expect, i.e. more than five words in the name.&lt;/P&gt;&lt;P&gt;But as soon as I get name like "aaa_bbb_ccc" (quite unexpected, but totally real) I get an error when indexing into my list.&lt;/P&gt;&lt;P&gt;Question: How do I index into not 5, but the least of 5 and the N Items of the list? Rather than write an IF statement to figure out which is less?&lt;/P&gt;</description>
    <pubDate>Fri, 09 Jun 2023 17:03:35 GMT</pubDate>
    <dc:creator>miguello</dc:creator>
    <dc:date>2023-06-09T17:03:35Z</dc:date>
    <item>
      <title>Indexing into a list without errors</title>
      <link>https://community.jmp.com/t5/Discussions/Indexing-into-a-list-without-errors/m-p/518455#M74449</link>
      <description>&lt;P&gt;Let's say I have a file name that I parse into separate parts like so:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;nameWords = Words(name, "_")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Let's say I want to make a short name out of the first five words of the original name:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;shortName = Concat Items( nameWords[{1, 2, 3, 4, 5}], "_" );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Everything works fine while I'm getting names in the format that I expect, i.e. more than five words in the name.&lt;/P&gt;&lt;P&gt;But as soon as I get name like "aaa_bbb_ccc" (quite unexpected, but totally real) I get an error when indexing into my list.&lt;/P&gt;&lt;P&gt;Question: How do I index into not 5, but the least of 5 and the N Items of the list? Rather than write an IF statement to figure out which is less?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 17:03:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Indexing-into-a-list-without-errors/m-p/518455#M74449</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2023-06-09T17:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: Indexing into a list without errors</title>
      <link>https://community.jmp.com/t5/Discussions/Indexing-into-a-list-without-errors/m-p/518460#M74450</link>
      <description>&lt;P&gt;There you go:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;shortName = Concat Items(nameWords[1::Min(NItems(nameWords), 5)])&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Jul 2022 06:42:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Indexing-into-a-list-without-errors/m-p/518460#M74450</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2022-07-07T06:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: Indexing into a list without errors</title>
      <link>https://community.jmp.com/t5/Discussions/Indexing-into-a-list-without-errors/m-p/518510#M74456</link>
      <description>&lt;P&gt;You could also use &lt;A href="https://www.jmp.com/support/help/en/16.2/#page/jmp/character-functions-2.shtml?os=win&amp;amp;source=application#ww2479282" target="_blank" rel="noopener"&gt;Left()&lt;/A&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

a = "1_2_3_4_5_6_7_8";
b = "1_2_3";

Show(Concat Items(Left(Words(a, "_"), 5), "_"));
Show(Concat Items(Left(Words(b, "_"), 5), "_"));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-jsl"&gt;&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2022 09:30:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Indexing-into-a-list-without-errors/m-p/518510#M74456</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-07-07T09:30:07Z</dc:date>
    </item>
  </channel>
</rss>

