Skip to main content
February 10, 2025
Question

How to remove next line or new line char from last character onwards in any text string

  • February 10, 2025
  • 4 replies
  • 0 views

We have test like below

" Need modification.

Remove last line

"

In this example, we just need to remove next line char after remove last line string. We still need to keep next line after Need modification.

We are generating some documents and formatting should not change if users has entered next line in between the lines but only last line should be removed as soon as Users entered Save.

trim will not work here as it will remove from all the text

4 replies

andrewh6762
February 11, 2025

This does require an Appian developed plugin ( [mention:5249ebce040e4a53a9c2d98862b7c1d4:f7d226abd59f475c9d224a79e3f0ec07]) but is the quickest way I can think of. It just says replace any new line or carriage return at the end of an input and replace it with nothing.

a!localVariables(
  local!input: " Need modification.

Remove last line

",
  regexreplaceall(
    "(\r|\n){1,}$",
    local!input,
    ""
  )
)

The regular expression "(\r|\n){1,}$" means:

  • (\r|\n) means carriage return or new line
  • {1,} is 1 to any number of what preceded it (so any number of new lines or carriage returns)
  • $ means the end of a line
stefanhelzle0001
February 11, 2025

Split the string by line breaks, then reassemble the string ignoring empty items.

a!localVariables(
  local!input: " Need modification.

Remove last line

",
 joinarray(split(local!input, char(10)), char(10))
)

mikes0011
Brainy
February 11, 2025

I tried to post an answer much like Stefan's last night, but an error prevented me from submitting...  and still prevents me from submitting one with my actual code included :-/

mathieud0001
February 11, 2025

Same for me.