Appian Community and Appian Academy are being upgraded. As a part of the upgrade, Appian Community is currently in read-only mode, and user registration is disabled until August 3. We apologize for any inconvenience this may cause, but a more secure, stable, and performant Community experience is coming soon!

The new Appian Community launches August 3, followed by Appian Academy on August 7. During the migration, Appian Community Edition, Appian Academy, Documentation, Certifications, Instructor-led Customer Training, Partner Sales Training & Accreditation, and Forum (for Appian Partners and Customers only) will remain available.

find duplicate characters count in a string

input: "Banana",

output: "B---------------1" , "aaa---------------3", "nn---------------2" 

any one try it anthor way ..

{

a!localVariables(
local!data: "Banana",
local!len: len(local!data),
local!merge: union(
a!forEach(
items: enumerate(local!len) + 1,
expression: local!data[fv!index]
),
a!forEach(
items: enumerate(local!len) + 1,
expression: local!data[fv!index]
)
),
local!all: a!forEach(
items: enumerate(local!len) + 1,
expression: local!data[fv!index]
),
a!forEach(
items: local!merge,
expression: index(
local!data,
wherecontains(fv!item, local!all),
{}
) & "---------------" & count(wherecontains(fv!item, local!all))
)
)

}

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Hi,

    Another way to achieve this logic

    a!localVariables(
      local!word: "Banana",
      a!forEach(
        items: {
          "A","B","C","D","E","F","G","H", "I","J","K","L",
          "M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"
        },
        expression: a!localVariables(
          local!count: if(
            regexmatch(fv!item, upper(local!word), 1) > 0,
            count(regexallmatches(fv!item,local!word)),
            {}
          ),
          if(
            a!isNullOrEmpty(local!count),
            {},
            concat(repeat(local!count, fv!item), "-------", local!count)
          )
        )
      )
    )

Reply
  • 0
    Certified Lead Developer

    Hi,

    Another way to achieve this logic

    a!localVariables(
      local!word: "Banana",
      a!forEach(
        items: {
          "A","B","C","D","E","F","G","H", "I","J","K","L",
          "M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"
        },
        expression: a!localVariables(
          local!count: if(
            regexmatch(fv!item, upper(local!word), 1) > 0,
            count(regexallmatches(fv!item,local!word)),
            {}
          ),
          if(
            a!isNullOrEmpty(local!count),
            {},
            concat(repeat(local!count, fv!item), "-------", local!count)
          )
        )
      )
    )

Children