Page 1 of 1

manipulate multi lines text

Posted: 24 Aug 2019 08:30
by tsolignani
I have a variable with multilines text, f.i.:

"Q
É
E
R
R
T
Y
U
D"

I would like to remove carriage returns, put every line into a single line, but separated with a comma.

F.i.:

"Q,E,R,R" ecc.

I would I do that?

Thank you.

Re: manipulate multi lines text

Posted: 24 Aug 2019 14:48
by soutre
Carriage return is represented by \n in the string. So if you'd like to remove them, try running a replace on it. Give this a try:

Code: Select all

var="a\nb\nc\nd\ne\nf";

log(var);

log(replace(var,"\n",","));
Should look like this:

Code: Select all

a
b
c
d
e
f


a,b,c,d,e,f

Re: manipulate multi lines text

Posted: 24 Aug 2019 19:20
by tsolignani
Thank you, I'll try that.

Re: manipulate multi lines text

Posted: 24 Aug 2019 19:25
by tsolignani
It does work! But why using the log function? Thanks again.

Re: manipulate multi lines text

Posted: 25 Aug 2019 03:22
by soutre
I think it's a bit easier to use the log function to show how it may appear? This way there's no need to create a dialog box or run a debug conditional on the script. Just put the data and hit execute and view the log. But good point and it's not necessary to include the log. Though it could be good practice for certain flows for debugging purposes.

Re: manipulate multi lines text

Posted: 25 Aug 2019 08:30
by tsolignani
Understood, thank you. It is a good idea indeed!

Re: manipulate multi lines text

Posted: 25 Aug 2019 17:59
by Desmanto
log() makes it easier to see the result and copy it forum. It works best with the string/number. But for interactive result viewing, use debug dialog. If you have map/list object, you should use debug dialog to dig down the value in each nested object. I usually remove the debug dialog once the testing is done.

Re: manipulate multi lines text

Posted: 25 Aug 2019 18:29
by tsolignani
Really interesting, thank you.