<?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: Combining two strings in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Combining-two-strings/m-p/392993#M64331</link>
    <description>&lt;P&gt;Fantastic.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Sun, 13 Jun 2021 20:40:18 GMT</pubDate>
    <dc:creator>Yotam</dc:creator>
    <dc:date>2021-06-13T20:40:18Z</dc:date>
    <item>
      <title>Combining two strings</title>
      <link>https://community.jmp.com/t5/Discussions/Combining-two-strings/m-p/392962#M64327</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have 2 columns that contain strings in the following format:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;string1 = 1;0;2;0;0;8;0
string2 = 0;1;0;3;5;0;13&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note 1: Both strings contain the same number of ";" (but they are not necessarily the same length).&lt;/P&gt;
&lt;P&gt;Note 2: The two strings have 0's in alternating positions.&lt;/P&gt;
&lt;P&gt;Note 3: A string can contain two 0's in a row (separated by ";") as long as the other string have two non-zero terms in a row at the same positions.&lt;/P&gt;
&lt;P&gt;I want to create a new column (string3) which is the result of merging the two columns without the 0's. For the example above:&lt;/P&gt;
&lt;PRE&gt;string3 = 1;1;2;3;5;8;13&lt;/PRE&gt;
&lt;P&gt;So the string3 should have the same number of ";" as string1 and string2, and must contain all the terms between the ";" by order, with no 0's.&lt;/P&gt;
&lt;P&gt;Is there a way to do it using simple formulas only? Alternatively, using other methods such as loops?&lt;/P&gt;
&lt;P&gt;Please see attached file.&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Yotam&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:31:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Combining-two-strings/m-p/392962#M64327</guid>
      <dc:creator>Yotam</dc:creator>
      <dc:date>2023-06-10T23:31:46Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two strings</title>
      <link>https://community.jmp.com/t5/Discussions/Combining-two-strings/m-p/392979#M64328</link>
      <description>&lt;P&gt;Here is a formula that will work.&amp;nbsp; I have attached a new data table with a new formula column&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;w = 1;
newString = "";
While( Word( w, :string1, ";" ) != "",
	If( newString != "",
		newString = newString || ","
	);
	If( Word( w, :string1, ";" ) != "0",
		newString = newString || Word( w, :string1, ";" ),
		newString = newString || Word( w, :string2, ";" )
	);
	w++;
);
newString;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The formula does not check for the situation where zeros are found in the same location on both strings, nor for the situation where non zeros might appear in the same position on both strings.&amp;nbsp; No rules were defined as to how to handle such situations.&amp;nbsp; If such issues need to be checked on, modification of the formula will be a simple matter.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Jun 2021 12:33:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Combining-two-strings/m-p/392979#M64328</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-06-13T12:33:03Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two strings</title>
      <link>https://community.jmp.com/t5/Discussions/Combining-two-strings/m-p/392985#M64330</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/5080"&gt;@DonMcCormack&lt;/a&gt;- I think this might be a great challenge problem.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;how to catch and deal with errors in the strings (non-numbers, mismatched zeros, not same length)&lt;/LI&gt;&lt;LI&gt;how to make it fast for 1E6 semicolons&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;edit: Using the JMP 16 &lt;EM&gt;For Each Across&lt;/EM&gt; loop:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;string1 = "1;0;2;0;0;8;0";
string2 = "0;1;0;3;5;0;13";

result = "";
For Each( {{w1, w2}, idx}, across( Words( string1, ";" ), Words( string2, ";" ) ),
    result ||= (If( idx &amp;gt; 1, ",", "" ) || If( w1 == "0", w2, w1 ))
);
result;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;"1,1,2,3,5,8,13"&lt;/P&gt;</description>
      <pubDate>Sun, 13 Jun 2021 16:15:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Combining-two-strings/m-p/392985#M64330</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-06-13T16:15:36Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two strings</title>
      <link>https://community.jmp.com/t5/Discussions/Combining-two-strings/m-p/392993#M64331</link>
      <description>&lt;P&gt;Fantastic.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Sun, 13 Jun 2021 20:40:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Combining-two-strings/m-p/392993#M64331</guid>
      <dc:creator>Yotam</dc:creator>
      <dc:date>2021-06-13T20:40:18Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two strings</title>
      <link>https://community.jmp.com/t5/Discussions/Combining-two-strings/m-p/392994#M64332</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Unfortunately I currently don't have JMP16 yet, but this solution sure looks very elegant!&lt;/P&gt;</description>
      <pubDate>Sun, 13 Jun 2021 20:46:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Combining-two-strings/m-p/392994#M64332</guid>
      <dc:creator>Yotam</dc:creator>
      <dc:date>2021-06-13T20:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two strings</title>
      <link>https://community.jmp.com/t5/Discussions/Combining-two-strings/m-p/393865#M64427</link>
      <description>&lt;P&gt;While&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt;&amp;nbsp;gave you some interesting and useful options, if I've understood your situation correctly, it can be done in a formula without loops.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the formula I ended up with, first as a picture and then in JSL (which can be pasted into the Formula Editor).&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2021-06-16_17-05-06.880.png" style="width: 637px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/33592i59B1BFCBF48C3AAB/image-dimensions/637x131?v=v2" width="637" height="131" role="button" title="2021-06-16_17-05-06.880.png" alt="2021-06-16_17-05-06.880.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( !Is Missing( :string1 ) &amp;amp; !Is Missing( :string1 ),
	string1list = Words( :string1, ";" );
	string2list = Words( :string2, ";" );
	Concat Items( string1list[Loc( string1list, "0" )] = string2list[Loc( string1list, "0" )], ";" );
,
	""
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This uses the &lt;A href="https://www.jmp.com/support/help/en/16.0/#page/jmp/list-functions.shtml#ww2491421" target="_blank"&gt;Words()&lt;/A&gt; function to convert your strings to lists. It uses the &lt;A href="https://www.jmp.com/support/help/en/16.0/#page/jmp/loc-functions.shtml" target="_self"&gt;Loc()&lt;/A&gt; function to return a matrix of locations of the 0s in string1 and uses that as a index for both string1list (on the left side of an assignment) and string2list (on the right side of that assignment). Finally, the &lt;A href="https://www.jmp.com/support/help/en/16.0/#page/jmp/list-functions.shtml#ww4578477" target="_self"&gt;Concat Items()&lt;/A&gt; function converts the list back into a semicolon delimited string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If any of this is confusing or doesn't make sense, let me know and I'll explain further.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jun 2021 21:14:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Combining-two-strings/m-p/393865#M64427</guid>
      <dc:creator>Jeff_Perkinson</dc:creator>
      <dc:date>2021-06-16T21:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two strings</title>
      <link>https://community.jmp.com/t5/Discussions/Combining-two-strings/m-p/393881#M64430</link>
      <description>&lt;P&gt;I see this already has a few solutions but since you used Fibonacci numbers you got my attention ;)&lt;/img&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is another formula that operates on the strings directly (assuming they are stored in columns named string1 and string2, respectively) by converting them to matrices, adding the matrices, and converting the result back to a string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Brady&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Substitute( Char( Parse( "[" || Substitute( :string1, ";", "," ) || "]" ) + Parse( "[" || Substitute( :string2, ";", "," ) || "]" ) ),
	"[", "",
	"]", "",
	",", ";",
	" ", ""
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, I'm not sure whether it is feasible for you to use comma separators instead of semicolons, but if this is done, the formula becomes a little simpler.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Substitute( Char( Eval( Parse( Eval Insert( "[^:string1^] + [^:string2^]" ) ) ) ),
	"[", "",
	"]", "",
	" ", ""
)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Jun 2021 22:58:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Combining-two-strings/m-p/393881#M64430</guid>
      <dc:creator>brady_brady</dc:creator>
      <dc:date>2021-06-16T22:58:23Z</dc:date>
    </item>
  </channel>
</rss>

