<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Count the characters matching alphabets</title><link>https://community.appian.com/discussions/f/rules/20866/count-the-characters-matching-alphabets</link><description>Hello, 
 how to build an expression rule which has 2 inputs - 1 is string, 2nd is alphabet. print the count of characters matching alphabet with the string 
 (Umbrella to expected Result -u1m1b1r1e1l2a1)</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Count the characters matching alphabets</title><link>https://community.appian.com/thread/81264?ContentTypeID=1</link><pubDate>Thu, 29 Apr 2021 16:22:22 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:39095b7b-0669-4d8b-a5f9-9089fd8ba1b9</guid><dc:creator>Bharath Maruthamuthu</dc:creator><description>&lt;p&gt;Thank you Chris.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Count the characters matching alphabets</title><link>https://community.appian.com/thread/81263?ContentTypeID=1</link><pubDate>Thu, 29 Apr 2021 16:21:15 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:d67174a5-671d-4490-b7f9-e03ec1c8365e</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;Sure, basically here we are splitting the input string into an array, utilizing union() to remove duplicate characters, and creating a string of each unique character plus the count of appearances in the original input.&amp;nbsp; Adding some comments as well:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;a!localVariables(
  local!alphabet: &amp;quot;abcdefghijklmnopqrstuvwxyz&amp;quot;, /* input for which letters to consider */
  local!input: &amp;quot;Umbrella&amp;quot;, /* string to evaluate */
  
  /* split the input string into an array of characters u-m-b-r-e-l-l-a */
  local!inputArray: a!forEach(
    items: 1+enumerate(len(local!input)),
    expression: lower(charat(local!input,fv!index))
  ),
  local!chars: union(local!inputArray,local!inputArray), /* array of unique characters only u-m-b-r-e-l-a */
  
  joinarray( /* combine forEach array into a single string */
    reject(
      fn!isnull, /* remove values not included in the input string */
      a!forEach(
        items: local!chars, /* loop unique characters */
        expression: if(
          find(fv!item,local!alphabet,1)&amp;gt;0, /* is this character in the alphabet string to consider? */
          concat( /* combine */
            fv!item, /* current character */
            count(wherecontains(fv!item,local!inputArray)) /* number of appearances */
          ),
          null
        )
      )
    )
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Count the characters matching alphabets</title><link>https://community.appian.com/thread/81261?ContentTypeID=1</link><pubDate>Thu, 29 Apr 2021 16:00:11 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:f6315d20-89be-4e8d-a6b1-55db4ebda2de</guid><dc:creator>Bharath Maruthamuthu</dc:creator><description>&lt;p&gt;Chris, Can you please give the high level of the&amp;nbsp; code design which you have given. So that it can be clear.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Count the characters matching alphabets</title><link>https://community.appian.com/thread/81260?ContentTypeID=1</link><pubDate>Thu, 29 Apr 2021 15:48:49 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1b988fd5-1cc8-4c38-9b40-4c47eb4fd2d6</guid><dc:creator>Bharath Maruthamuthu</dc:creator><description>&lt;p&gt;Thank you. this works&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Count the characters matching alphabets</title><link>https://community.appian.com/thread/81259?ContentTypeID=1</link><pubDate>Thu, 29 Apr 2021 15:42:14 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a4c5a673-55e8-4dd5-8994-795d38fc71e9</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;Try this expression, it should work for you assuming you want to only return the first instance (with count) of each character.&amp;nbsp; E.g., &amp;quot;Caterpillar&amp;quot; = &amp;quot;&lt;span&gt;&lt;span class="CollapsibleOutputNode---print_value"&gt;c1a2t1e1r2p1i1l2&lt;/span&gt;&lt;/span&gt;&amp;quot;.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;a!localVariables(
  local!alphabet: &amp;quot;abcdefghijklmnopqrstuvwxyz&amp;quot;,
  local!input: &amp;quot;Umbrella&amp;quot;,
  
  local!inputArray: a!forEach(
    items: 1+enumerate(len(local!input)),
    expression: lower(charat(local!input,fv!index))
  ),
  local!chars: union(local!inputArray,local!inputArray),
  
  joinarray(
    reject(
      fn!isnull,
      a!forEach(
        items: local!chars,
        expression: if(
          find(fv!item,local!alphabet,1)&amp;gt;0,
          concat(
            fv!item,
            count(wherecontains(fv!item,local!inputArray))
          ),
          null
        )
      )
    )
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>