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.
manipulate multi lines text
Moderator: Martin
- tsolignani
- Posts: 187
- Joined: 12 Jan 2019 11:53
- Location: Vignola, Mo, Italy
- Contact:
Re: manipulate multi lines text
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:
Should look like this:
Code: Select all
var="a\nb\nc\nd\ne\nf";
log(var);
log(replace(var,"\n",","));
Code: Select all
a
b
c
d
e
f
a,b,c,d,e,f
- tsolignani
- Posts: 187
- Joined: 12 Jan 2019 11:53
- Location: Vignola, Mo, Italy
- Contact:
Re: manipulate multi lines text
Thank you, I'll try that.
- tsolignani
- Posts: 187
- Joined: 12 Jan 2019 11:53
- Location: Vignola, Mo, Italy
- Contact:
Re: manipulate multi lines text
It does work! But why using the log function? Thanks again.
Re: manipulate multi lines text
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.
- tsolignani
- Posts: 187
- Joined: 12 Jan 2019 11:53
- Location: Vignola, Mo, Italy
- Contact:
Re: manipulate multi lines text
Understood, thank you. It is a good idea indeed!
Re: manipulate multi lines text
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), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
- tsolignani
- Posts: 187
- Joined: 12 Jan 2019 11:53
- Location: Vignola, Mo, Italy
- Contact:
Re: manipulate multi lines text
Really interesting, thank you.