<?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: Search a list of strings for a partial string in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Search-a-list-of-strings-for-a-partial-string/m-p/222796#M44452</link>
    <description>&lt;P&gt;I think the loop may be a good choice; most of the work is in the contains function, not the loop overhead.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;x={"34565467456745673456345634563456abca","34563456456745674534563456346accca","34456745674556345634563456accda"};
for(i=1,i&amp;lt;20,i+=1,
x=x||x;
);
nitems(x); // 1572864
result={};
start=tickseconds();
for(i=1,i&amp;lt;=nitems(x),i+=1,
	if(contains(x[i],"ccc"),insertinto(result,i))
);
stop=tickseconds();
show(nitems(x)/nitems(result),stop-start);// 3:1, &amp;lt;1 second&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;One of the three strings contains the search pattern, the result list is 1/3 the size of the source. 1 second for 1.5 million items seems reasonable. What size list, typical item length, and what time requirement do you have?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another approach, not as good. Avoids the explicit loop but copies the data into a table and uses row selection:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;x={"34565467456745673456345634563456abca","34563456456745674534563456346accca","34456745674556345634563456accda"};
for(i=1,i&amp;lt;20,i+=1,
x=x||x;
);
nitems(x); // 1572864

start=tickseconds();
dt = New Table( "Untitled",
	New Column( "Column 1", Character, "Nominal", Set Values( x ) )
);
stop=tickseconds();
show(stop-start); // 1.3 sec

start=tickseconds();
dt&amp;lt;&amp;lt;selectwhere(contains(column1,"ccc"));
list=dt&amp;lt;&amp;lt;getselectedrows;
stop=tickseconds();
show(stop-start); // 1 sec&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;JMP added better list support in JMP 13; if you are using an older version, read this post&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.jmp.com/t5/Uncharted/Fast-List/ba-p/28947" target="_blank" rel="noopener"&gt;https://community.jmp.com/t5/Uncharted/Fast-List/ba-p/28947&lt;/A&gt;&lt;/P&gt;&lt;P&gt;to make JMP &amp;lt; 13 faster.&lt;/P&gt;</description>
    <pubDate>Fri, 23 Aug 2019 03:39:21 GMT</pubDate>
    <dc:creator>Craige_Hales</dc:creator>
    <dc:date>2019-08-23T03:39:21Z</dc:date>
    <item>
      <title>Search a list of strings for a partial string</title>
      <link>https://community.jmp.com/t5/Discussions/Search-a-list-of-strings-for-a-partial-string/m-p/222778#M44447</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to find a way to search through a list of strings for all items that contain a partial string. I know this can be done using a For loop, but the list that I will be running this script on is very large and For loops take a very long time. I am wondering if there is some function out there similar to Loc(list, string) that will find the items that have the partial string.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just as an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;list= {football, hockey, baseball, tennis};

Loc(list, "ball");&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Would ideally return [1, 3].&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2019 22:57:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Search-a-list-of-strings-for-a-partial-string/m-p/222778#M44447</guid>
      <dc:creator>aallman</dc:creator>
      <dc:date>2019-08-22T22:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: Search a list of strings for a partial string</title>
      <link>https://community.jmp.com/t5/Discussions/Search-a-list-of-strings-for-a-partial-string/m-p/222796#M44452</link>
      <description>&lt;P&gt;I think the loop may be a good choice; most of the work is in the contains function, not the loop overhead.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;x={"34565467456745673456345634563456abca","34563456456745674534563456346accca","34456745674556345634563456accda"};
for(i=1,i&amp;lt;20,i+=1,
x=x||x;
);
nitems(x); // 1572864
result={};
start=tickseconds();
for(i=1,i&amp;lt;=nitems(x),i+=1,
	if(contains(x[i],"ccc"),insertinto(result,i))
);
stop=tickseconds();
show(nitems(x)/nitems(result),stop-start);// 3:1, &amp;lt;1 second&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;One of the three strings contains the search pattern, the result list is 1/3 the size of the source. 1 second for 1.5 million items seems reasonable. What size list, typical item length, and what time requirement do you have?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another approach, not as good. Avoids the explicit loop but copies the data into a table and uses row selection:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;x={"34565467456745673456345634563456abca","34563456456745674534563456346accca","34456745674556345634563456accda"};
for(i=1,i&amp;lt;20,i+=1,
x=x||x;
);
nitems(x); // 1572864

start=tickseconds();
dt = New Table( "Untitled",
	New Column( "Column 1", Character, "Nominal", Set Values( x ) )
);
stop=tickseconds();
show(stop-start); // 1.3 sec

start=tickseconds();
dt&amp;lt;&amp;lt;selectwhere(contains(column1,"ccc"));
list=dt&amp;lt;&amp;lt;getselectedrows;
stop=tickseconds();
show(stop-start); // 1 sec&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;JMP added better list support in JMP 13; if you are using an older version, read this post&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.jmp.com/t5/Uncharted/Fast-List/ba-p/28947" target="_blank" rel="noopener"&gt;https://community.jmp.com/t5/Uncharted/Fast-List/ba-p/28947&lt;/A&gt;&lt;/P&gt;&lt;P&gt;to make JMP &amp;lt; 13 faster.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Aug 2019 03:39:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Search-a-list-of-strings-for-a-partial-string/m-p/222796#M44452</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2019-08-23T03:39:21Z</dc:date>
    </item>
  </channel>
</rss>

