manipulate multi lines text

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
tsolignani
Posts: 50
Joined: 12 Jan 2019 11:53
Location: Vignola, Mo, Italy
Contact:

manipulate multi lines text

Post by tsolignani » 24 Aug 2019 08:30

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.

soutre
Posts: 11
Joined: 18 Aug 2019 07:01

Re: manipulate multi lines text

Post by soutre » 24 Aug 2019 14:48

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

User avatar
tsolignani
Posts: 50
Joined: 12 Jan 2019 11:53
Location: Vignola, Mo, Italy
Contact:

Re: manipulate multi lines text

Post by tsolignani » 24 Aug 2019 19:20

Thank you, I'll try that.

User avatar
tsolignani
Posts: 50
Joined: 12 Jan 2019 11:53
Location: Vignola, Mo, Italy
Contact:

Re: manipulate multi lines text

Post by tsolignani » 24 Aug 2019 19:25

It does work! But why using the log function? Thanks again.

soutre
Posts: 11
Joined: 18 Aug 2019 07:01

Re: manipulate multi lines text

Post by soutre » 25 Aug 2019 03:22

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.

User avatar
tsolignani
Posts: 50
Joined: 12 Jan 2019 11:53
Location: Vignola, Mo, Italy
Contact:

Re: manipulate multi lines text

Post by tsolignani » 25 Aug 2019 08:30

Understood, thank you. It is a good idea indeed!

User avatar
Desmanto
Posts: 1981
Joined: 21 Jul 2017 17:50

Re: manipulate multi lines text

Post by Desmanto » 25 Aug 2019 17:59

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.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), Resurrection Remix Official 7.0.2 20190829, Pie 9.0, Rooted.

User avatar
tsolignani
Posts: 50
Joined: 12 Jan 2019 11:53
Location: Vignola, Mo, Italy
Contact:

Re: manipulate multi lines text

Post by tsolignani » 25 Aug 2019 18:29

Really interesting, thank you.

Post Reply