Skip to main content
akasht489174
August 31, 2021
Question

Remove the duplicate values from a text rule input?

  • August 31, 2021
  • 13 replies
  • 1 view

My requirement is to remove the duplicate values from a rule input of type text. Here is a sample input and output.

Input: Hello hello Hello there there past pastures

Output: Hello there past pastures

13 replies

richardm900458
August 31, 2021

is that an array of string values or a single string?

akasht489174
August 31, 2021

single string

richardm900458
August 31, 2021

in any case there is no "simple" method or function to archive that.
1.) You need to cut it into pieces (word for word)
2.) compare the different values to each other
3.) remove the values you don't want to have.

Spontanously I would suggest an expression with extract(), search() perhaps cleanwith() 
Sorry no final solution for that issue on hand. 
-> docs.appian.com/.../Appian_Functions.html

stefanhelzle0001
Brainy
August 31, 2021

You use split() to turn it into a list and union() to remove duplicates.

richardm900458
August 31, 2021

good approach. perhaps user lower() or proper() in combination with the split results to avoid "hello" and "Hello" treated as different values.

harshas2775
August 31, 2021

you can first do split() on spaces and then take union() of the split array to filter out repeated strings. Lastly concat the result with spaces in between.

stewart.burchell
August 31, 2021

There maybe more elegant ways, but something like this:

a!localVariables(
  local!trimmed: fn!trim(ri!inputString),
  local!split: fn!split(local!trimmed, " "),
  local!lower: fn!lower(local!split),
  local!union: fn!union(local!lower, local!lower),
  local!result: a!forEach(
    items: local!union,
    expression: if(
      fv!isFirst,
      concat(fn!proper(fv!item), " "),
      concat(fv!item, " ")
    )
  ),
  fv!concat(local!result)
)

Notes:

  1. fn!trim() removes all unnecessary spaces (in case you have more than one space between the individual strings) 
  2. fn!split() breaks up the input strings into an array so they can be processed independently
  3. fn!lower() makes all of the strings into lower case so that, for example, all "Hello" items are the same
  4. fn!union() removes duplicate strings from the array
  5. the a!forEach() allows us to treat the very first item in the array differently from the others, so we can use fn!proper() to capitalize the first letter for just the first string. For all items we add single space so that...
  6. ...we can then concatenate all of the items in the array to a single output string 
richardm900458
August 31, 2021

hi stewart, is there an guide for fn! functions somewhere ? not all functions are available as fn! but is there any simple rule like all functions without a! or a page to explain them. 
Just curious.... 

August 31, 2021

Hi AKASH T,

can you try this one

a!localVariables(
local!string:union(split(lower("Hello hello Hello there there past pastures")," "),split(lower("Hello hello Hello there there past pastures")," ")),
substitute(tostring(local!string),";"," ")
)