How to remove duplicate letters from the string without changing case of letters
input "Deleted"
output "Delt"
Discussion posts and replies are publicly visible
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 ) ) ) ) )
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] ) ), "" ) )
Hi vickyr583585 ,
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))
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.