Remove Duplicates Letters

Certified Senior Developer

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

input "Deleted"

output "Delt"

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    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
            )
          )
        )
      )
    )

Reply
  • 0
    Certified Lead Developer

    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
            )
          )
        )
      )
    )

Children
No Data