Skip to main content
Known Participant
June 29, 2025
Solved

Remove Duplicates Letters

  • June 29, 2025
  • 5 replies
  • 1 view

How to remove duplicate letters from the string without changing case of letters

input "Deleted"

output "Delt"

Best answer by stefanhelzle0001

A shorter version. I check each character whether it already is part of the substring before it.

a!localVariables(
  local!text: "Deleted",
  joinarray(
    a!foreach(
      items: enumerate(len(local!text)),
      expression: if(
        a!isInText(left(local!text, fv!item), local!text[fv!index]),
        "",
        local!text[fv!index]
      )
    ),
    ""
  )
)

5 replies

harshas2775
June 29, 2025

With the use of functions and loops this can be achieved. First you need to split the text into a character array. Then remove the duplicates from the character array. Result will have unique characters - uppercase and lowercase will be in this array as they are unique still! Lastly we identify/reject the duplicates doing a case match and return the output as expected, in the same case and order as present in original text.

Below is a code with the solution for this interesting question. Hope it helps! 

a!localVariables(
  local!text: "Deleted",
  local!charArray: a!foreach(
    enumerate(len(local!text)) + 1,
    local!text[fv!item]
  ),
  local!unique: union(local!charArray, local!charArray),
  joinarray(
    a!foreach(
      local!unique,
      if(
        fv!isFirst = 1,
        fv!item,
        if(
          length(
            wherecontains(lower(fv!item), lower(local!unique))
          ) > 1,
          {},
          fv!item
        )
      )
    )
  )
)

stefanhelzle0001
June 30, 2025

A shorter version. I check each character whether it already is part of the substring before it.

a!localVariables(
  local!text: "Deleted",
  joinarray(
    a!foreach(
      items: enumerate(len(local!text)),
      expression: if(
        a!isInText(left(local!text, fv!item), local!text[fv!index]),
        "",
        local!text[fv!index]
      )
    ),
    ""
  )
)

Known Participant
October 9, 2025

An alternate solution

a!localVariables(
  local!word: "DeletEd",
  local!letters: char(code(local!word)),
  local!uniq: union(local!letters, local!letters),
  local!result: a!forEach(
    local!uniq,
  
    wherecontains(1, search(fv!item, local!uniq))[1]
  ),
  index(
    local!uniq,
    union(local!result, local!result),
    {}
  )
)

June 30, 2025

Hi [mention:bbb0369284f149fc8749ddcb409331e8:e9ed411860ed4f2ba0265705b8793d05] ,

you can try with below code.

a!localVariables(
local!input: "appian",
local!chars: char(code(local!input)),
local!char: a!forEach(
items: union(local!chars, local!chars),
expression: left(cleanwith(local!input, fv!item), 1),

),
joinarray(local!char)
)

harshas2775
June 30, 2025

If the text has different cases like in "Deleted' - d comes twice in lower as well as upper case -  then this does not yield expected output.