<?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: Covert a string to a list in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Convert-a-string-to-a-list/m-p/722229#M90420</link>
    <description>&lt;P&gt;Hi Jim,&lt;/P&gt;&lt;P&gt;&amp;nbsp;How would you approach this if you have a string, and a comma is where you want to stop separating the string.&amp;nbsp;&lt;BR /&gt;For example,&amp;nbsp;&lt;/P&gt;&lt;P&gt;converting this " C = "It is, raining, very, hard today" to b = {"It is" , "raining" , "very", "hard today" }&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 05 Feb 2024 23:43:38 GMT</pubDate>
    <dc:creator>RA899</dc:creator>
    <dc:date>2024-02-05T23:43:38Z</dc:date>
    <item>
      <title>Convert a string to a list</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-a-string-to-a-list/m-p/38881#M22731</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any builtin function to convert a string to a list? For example, I have a string "abcd1234cdef5678" and I want it to be converted to {"abcd", "1234", "cdef, "5678""}.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;Ahmad&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 12:34:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-a-string-to-a-list/m-p/38881#M22731</guid>
      <dc:creator>aumair</dc:creator>
      <dc:date>2017-06-28T12:34:42Z</dc:date>
    </item>
    <item>
      <title>Re: Covert a string to a list</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-a-string-to-a-list/m-p/38884#M22734</link>
      <description>&lt;P&gt;I am not aware of such a function, but you could use this code or make it a function&lt;/P&gt;
&lt;PRE&gt;Names Default To Here( 1 );&lt;BR /&gt;TheString = "abcd1234cdef5678";&lt;BR /&gt;TheList = {};&lt;BR /&gt;i = 1;&lt;BR /&gt;While( Substr( TheString, i, 4 ) != "",&lt;BR /&gt; Insert Into( TheList, Substr( TheString, i, 4 ) );&lt;BR /&gt; i = i + 4;&lt;BR /&gt;);&lt;BR /&gt;&lt;BR /&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or here it is as a function&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;SeparateString = Function( {TheString},
	TheList = {};
	i = 1;
	While( Substr( TheString, i, 4 ) != "",
		Insert Into( TheList, Substr( TheString, i, 4 ) );
		i = i + 4;
	);
	TheList;
);

MyList = SeparateString("abcd1234cdef5678");&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 May 2017 03:39:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-a-string-to-a-list/m-p/38884#M22734</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2017-05-05T03:39:21Z</dc:date>
    </item>
    <item>
      <title>Re: Covert a string to a list</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-a-string-to-a-list/m-p/38886#M22736</link>
      <description>&lt;P&gt;Thanks a lot Jim!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 05:54:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-a-string-to-a-list/m-p/38886#M22736</guid>
      <dc:creator>aumair</dc:creator>
      <dc:date>2017-05-05T05:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: Covert a string to a list</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-a-string-to-a-list/m-p/38905#M22744</link>
      <description>&lt;P&gt;Take a look at the &lt;A href="http://www.jmp.com/support/help/13-1/List_Functions.shtml#2491421" target="_blank"&gt;&lt;FONT face="courier new,courier"&gt;Words()&lt;/FONT&gt;&lt;/A&gt; &amp;nbsp;function. If you can &lt;A href="http://www.jmp.com/support/help/13-1/Character_Functions.shtml" target="_self"&gt;define delimiters&lt;/A&gt; which separate the elements of the list then it will&amp;nbsp;work for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 13:59:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-a-string-to-a-list/m-p/38905#M22744</guid>
      <dc:creator>Jeff_Perkinson</dc:creator>
      <dc:date>2017-05-05T13:59:22Z</dc:date>
    </item>
    <item>
      <title>Re: Covert a string to a list</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-a-string-to-a-list/m-p/38935#M22756</link>
      <description>&lt;P&gt;Another technique:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;parts = {};
rc = Pat Match( "1234567890abcdefghijklmnopqrstuv", Pat Repeat( Pat Len( 4 ) &amp;gt;&amp;gt; parts[N Items( parts ) + 1] ) );
Show( parts );
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;parts = {"1234", "5678", "90ab", "cdef", "ghij", "klmn", "opqr", "stuv"};&lt;/P&gt;
&lt;P&gt;Jim's approach is better for short strings because the next person that maintains the JSL will understand it. For strings that are 10K or so, the pattern matching will be noticably faster.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="The pattern match (red curve) avoids reprocessing the string" style="width: 750px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/6113i1720B35C6C79660A/image-size/large?v=v2&amp;amp;px=999" role="button" title="compare.PNG" alt="The pattern match (red curve) avoids reprocessing the string" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;The pattern match (red curve) avoids reprocessing the string&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The is the JSL to make the graph...&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = New Table( "Untitled",
	Add Rows( 0 ),
	New Column( "n", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) ),
	New Column( "forloopTime", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) ),
	New Column( "patternTime", Numeric, "Continuous", Format( "Best", 12 ), Set Selected, Set Values( [] ) )
);

For( nstr = 1, nstr &amp;lt; 10000, nstr *= 2,
	dt &amp;lt;&amp;lt; addrows( 1 );
	dt:n = nstr * 4; // four substrings in the repeat...
	TheString = Repeat( "abcd1234cdef5678", nstr );
	start = Tick Seconds();
	TheList = {};
	i = 1;
	While( Substr( TheString, i, 4 ) != "",
		Insert Into( TheList, Substr( TheString, i, 4 ) );
		i = i + 4;
	);
	stop = Tick Seconds();
	dt:forloopTime = (stop - start);

	start = Tick Seconds();
	parts = {};
	rc = Pat Match( theString, Pat Repeat( Pat Len( 4 ) &amp;gt;&amp;gt; parts[N Items( parts ) + 1] ) );
	stop = Tick Seconds();
	dt:patternTime = (stop - start);
	Wait( 0 );
);

dt &amp;lt;&amp;lt; Graph Builder(
	Size( 764, 624 ),
	Show Control Panel( 0 ),
	Legend Position( "Inside Left" ),
	Variables( X( :n ), Y( :forloopTime ), Y( :patternTime, Position( 1 ) ) ),
	Elements( Points( X, Y( 1 ), Y( 2 ), Legend( 9 ) ), Smoother( X, Y( 1 ), Y( 2 ), Legend( 10 ) ) ),
	SendToReport(
		Dispatch( {}, "n", ScaleBox, {Min( -1453.48837209302 )} ),
		Dispatch( {}, "forloopTime", ScaleBox, {Format( "Best", 12 ), Min( -0.949803149606299 )} ),
		Dispatch( {}, "graph title", TextEditBox, {Set Text( "Compare algorithms" )} ),
		Dispatch( {}, "X title", TextEditBox, {Set Text( "n patterns " )} ),
		Dispatch( {}, "Y title", TextEditBox, {Set Text( "Seconds" )} ),
		Dispatch( {}, "400", LegendBox, {Set Title( "" )} )
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The reason the for loop example slows down on large strings: the substr function must find the location of &lt;EM&gt;each&lt;/EM&gt; substring, starting from the &lt;EM&gt;beginning&lt;/EM&gt;. The pattern match moves through the string &lt;EM&gt;once&lt;/EM&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 May 2017 23:12:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-a-string-to-a-list/m-p/38935#M22756</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2017-05-06T23:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: Covert a string to a list</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-a-string-to-a-list/m-p/722229#M90420</link>
      <description>&lt;P&gt;Hi Jim,&lt;/P&gt;&lt;P&gt;&amp;nbsp;How would you approach this if you have a string, and a comma is where you want to stop separating the string.&amp;nbsp;&lt;BR /&gt;For example,&amp;nbsp;&lt;/P&gt;&lt;P&gt;converting this " C = "It is, raining, very, hard today" to b = {"It is" , "raining" , "very", "hard today" }&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 23:43:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-a-string-to-a-list/m-p/722229#M90420</guid>
      <dc:creator>RA899</dc:creator>
      <dc:date>2024-02-05T23:43:38Z</dc:date>
    </item>
    <item>
      <title>Re: Covert a string to a list</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-a-string-to-a-list/m-p/722236#M90422</link>
      <description>&lt;P&gt;Update:&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have found an older thread about this from&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://community.jmp.com/t5/user/viewprofilepage/user-id/6878" target="_blank" rel="noopener"&gt;Jeff_Perkinson.&amp;nbsp;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;This is the link&amp;nbsp;&lt;A href="https://community.jmp.com/t5/Discussions/Using-several-characters-as-delimiter-for-the-Words-function/m-p/18307" target="_blank" rel="noopener"&gt;Solved: Using several characters as delimiter for the Words function - JMP User Community&amp;nbsp;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The solution that worked for me was using this method:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;words(substitute("Test1eeTest2", "ee", "!"),"!")

/*:

{"Test1", "Test2"}

&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks.&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Rakan&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2024 01:18:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-a-string-to-a-list/m-p/722236#M90422</guid>
      <dc:creator>RA899</dc:creator>
      <dc:date>2024-02-06T01:18:06Z</dc:date>
    </item>
    <item>
      <title>Re: Covert a string to a list</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-a-string-to-a-list/m-p/722237#M90423</link>
      <description>&lt;P&gt;Use the Words() function to split the string into a List with the elements of the being each of the substrings identified by the specified delimiter, in your case a comma.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);

C = "It is, raining, very, hard today";
b = Words( C, "," );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2024 01:47:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-a-string-to-a-list/m-p/722237#M90423</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-02-06T01:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: Covert a string to a list</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-a-string-to-a-list/m-p/772585#M95301</link>
      <description>&lt;P&gt;If converting string to list of single characters (a little different from OP's request but matches the title) then can do:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Items( "hello", "" );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Which returns:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;{"h", "e", "l", "l", "o"}&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Jul 2024 18:41:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-a-string-to-a-list/m-p/772585#M95301</guid>
      <dc:creator>bswedlove</dc:creator>
      <dc:date>2024-07-11T18:41:30Z</dc:date>
    </item>
  </channel>
</rss>

