Skip to main content
udayasain741
September 26, 2023
Question

Remove total words from a sentence

  • September 26, 2023
  • 4 replies
  • 0 views

Hi Team,

I would like to remove total words from a sentence, Below is the sentence

Are the machines property stickered(external communication)

I need to remove(external communication) from the above one, Strip with or clean with cant be used because it will remove other letters also

Any suggestions ?

Thanks

    4 replies

    September 26, 2023

    index(split("Are the machines property stickered(external communication)","("),1,{})

    jims1108
    September 26, 2023

    joinarray(split(ri!texttoclean,"(external communication)"))

    This will find the given string anywhere in the text and remove it, not just at the end. The other answer would break if the desired text also has a parenthesis in it

    mikes0011
    Brainy
    September 26, 2023

    The previous answer(s) will work, however I'd personally recommend going with a function that's targeted specifically to this sort of use case, rather than trying to play around with "split()" unnecessarily, and having to deal with the consequences of the fact that it naturally outputs an array (which you'd have to handle and account for).

    So for that I'd suggest "substitute()", which hunts for a whole sub-string and replaces it with a whole different sub-string (which can just be a blank value if desired).  That would end up looking like this:

    This also cleanly handles if the input string doesn't have the target substring for removal - in these cases the output is simply untouched.

    FYI the Appian Documentation has a comprehensive list of all Text Functions (as well as all other OOB functions), and I strongly recommend keeping the link handy.

    mathieud0001
    September 27, 2023

    Agree with Mike.

    You can also use reduce if you you're looking to replace a bunch of different text items in a string.

    a!localVariables(
      local!text: "Are the machines property stickered(external communication) something else",
      local!keys: { "(external communication)", "something else" },
      local!values: { "", "" },
      trim(
        reduce(
          substitute(_, _, _),
          local!text,
          merge(local!keys, local!values)
        )
      )
    )