<?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: Replace characters in the string in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Replace-characters-in-the-string/m-p/640453#M83784</link>
    <description>&lt;P&gt;Thanks a lot Jarmo&lt;/P&gt;</description>
    <pubDate>Thu, 08 Jun 2023 17:08:47 GMT</pubDate>
    <dc:creator>Jackie_</dc:creator>
    <dc:date>2023-06-08T17:08:47Z</dc:date>
    <item>
      <title>Replace characters in the string</title>
      <link>https://community.jmp.com/t5/Discussions/Replace-characters-in-the-string/m-p/640357#M83771</link>
      <description>&lt;P&gt;Hi JMP community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'm trying to write a jsl code that would take a column with a string in it, and in each row, replace the count with the values in the count column. The final results should look something like in the Results column&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any Suggestions?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 19:44:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Replace-characters-in-the-string/m-p/640357#M83771</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2023-06-09T19:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: Replace characters in the string</title>
      <link>https://community.jmp.com/t5/Discussions/Replace-characters-in-the-string/m-p/640366#M83774</link>
      <description>&lt;P&gt;The strings appear to follow the same pattern. Maybe use the words() function with either a space or " as the separator. Then use concatitems() to put it back together.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="capture.png" style="width: 900px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/53549i82A23A78C1938597/image-size/large?v=v2&amp;amp;px=999" role="button" title="capture.png" alt="capture.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jun 2023 14:12:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Replace-characters-in-the-string/m-p/640366#M83774</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2023-06-08T14:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: Replace characters in the string</title>
      <link>https://community.jmp.com/t5/Discussions/Replace-characters-in-the-string/m-p/640418#M83776</link>
      <description>&lt;P&gt;Regex is one other option&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Regex(:Results, "(BIN = \!".+\!") (\d+)(\!".+)", "\1 " || Char(:Count) || "\3")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but in this case I would use Words() + Concat Items() like Craige suggested (if the pattern is always same)&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jun 2023 15:36:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Replace-characters-in-the-string/m-p/640418#M83776</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-06-08T15:36:39Z</dc:date>
    </item>
    <item>
      <title>Re: Replace characters in the string</title>
      <link>https://community.jmp.com/t5/Discussions/Replace-characters-in-the-string/m-p/640422#M83777</link>
      <description>&lt;P&gt;Thanks Craig and Jarmo&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jun 2023 16:12:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Replace-characters-in-the-string/m-p/640422#M83777</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2023-06-08T16:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: Replace characters in the string</title>
      <link>https://community.jmp.com/t5/Discussions/Replace-characters-in-the-string/m-p/640447#M83782</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;I used Cragis logic to update the count in the string but it doesn't replaces the correct count string. I'm not sure what I am doing wrong. Can you take a look at my code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Assigns incorrect counts&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Here's the code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();
/// Get list of all the bins
binxx = Associative Array( :Bins[23:: N Rows( dt )] ) &amp;lt;&amp;lt; Get Keys;

delcols = {"", "	", "}"};
/// Remove garbage values																	
For( i = 1, i &amp;lt;= N Items( delcols ), i++,
	Remove From( binxx, As List( Loc( binxx, delcols[i] ) ) );
	
	
);

///Get rows where Bins column contains BIN = 
rows = dt &amp;lt;&amp;lt; get rows where( Contains( :Bins, "BIN = " ) );
total = {};

//Loop to calculate the count of each bins
For( i = 1, i &amp;lt;= N Items( binxx ), i++, 
	
	
	Insert Into( total, N Items( dt &amp;lt;&amp;lt; get rows where( :Bins == binxx[i] ) ) )
);
//create array to store bin and counts
arra = Associative Array( binxx, total );

//loop to modify the character count in the table

For( j = 1, j &amp;lt;= N Items( binxx ), j++,
	For( i = 2, i &amp;lt;= N Items( rows ), i++, 
	
		If( Contains( arra, Substr( :Bins[i], 8, 1 ) ), 
		
			x = Words( :Bins[rows[i]] );
			x[4] = Char( arra[binxx[j]] ); 

			:Bins[rows[i]] = Concat Items( x );

		)
	)
);


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jun 2023 19:15:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Replace-characters-in-the-string/m-p/640447#M83782</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2023-06-08T19:15:45Z</dc:date>
    </item>
    <item>
      <title>Re: Replace characters in the string</title>
      <link>https://community.jmp.com/t5/Discussions/Replace-characters-in-the-string/m-p/640452#M83783</link>
      <description>&lt;P&gt;I think the issue is with this line&lt;/P&gt;
&lt;PRE class="language-jsl"&gt;&lt;CODE&gt;x[4] = Char( arra[binxx[j]] ); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I would modify the loop to loop over the rows instead of associative array + rows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Current Data Table();
/// Get list of all the bins
binxx = Associative Array(:Bins[23 :: N Rows(dt)]) &amp;lt;&amp;lt; Get Keys;

delcols = {"", "	", "}"};
/// Remove garbage values																	
For(i = 1, i &amp;lt;= N Items(delcols), i++,
	Remove From(binxx, As List(Loc(binxx, delcols[i])));
);

///Get rows where Bins column contains BIN = 
rows = dt &amp;lt;&amp;lt; get rows where(Contains(:Bins, "BIN = "));
total = {};

//Loop to calculate the count of each bins
For(i = 1, i &amp;lt;= N Items(binxx), i++, 
	Insert Into(total, N Items(dt &amp;lt;&amp;lt; get rows where(:Bins == binxx[i])))
);

//create array to store bin and counts
arra = Associative Array(binxx, total);

//loop to modify the character count in the table
For(i = 1, i &amp;lt;= N Items(rows), i++, 
	x = Words(:Bins[rows[i]]);
	curbin = Substitute(x[3], "\!"", "");
	If(Contains(arra, curbin),
		x[4] = Char(arra[curbin]);
		:Bins[rows[i]] = Concat Items(x);
	,
		continue();
	);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Jun 2023 17:05:29 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Replace-characters-in-the-string/m-p/640452#M83783</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-06-08T17:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: Replace characters in the string</title>
      <link>https://community.jmp.com/t5/Discussions/Replace-characters-in-the-string/m-p/640453#M83784</link>
      <description>&lt;P&gt;Thanks a lot Jarmo&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jun 2023 17:08:47 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Replace-characters-in-the-string/m-p/640453#M83784</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2023-06-08T17:08:47Z</dc:date>
    </item>
  </channel>
</rss>

