How do I convert a multiline of text from an input box into a single line of text except I would put a string of characters to replace the carriage return?

from:

Hello
world
I
am
here.

to:

Hello~|~world~|~I~|~am~|~here.

Tried this and other variants but doesn't work.
txt = txt.split(ASCII(13)).join("~|~");