what exactly does the trim function do?

Post your questions and help other users.

Moderator: Martin

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

what exactly does the trim function do?

Post by tsolignani » 11 Jan 2020 10:49

Good morning everyone,

Maybe owing to my comprehension difficulties in English, I don't understand well what the trim function does.

Does it remove white spaces / blank only at the beginning and at the end of a string or all the white spaces into the string are replaced?

Will it work with carriage return characters as well (\n)?

Thank you.

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

Re: what exactly does the trim function do?

Post by Desmanto » 11 Jan 2020 17:49

Yes, all white space including tab (\t), newline either \r or \n. Example

Code: Select all

a = "\tHello World\t\n\r";
b = a + "123";
c = trim(a) + "123";
If you look at debug dialog, b show 123 below the line. While c use the trimmed a, and it shows 123 right next to the world.
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.

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

Re: what exactly does the trim function do?

Post by tsolignani » 11 Jan 2020 20:42

Thank you. So it does work only on white spaces left or right and not in the middle.

Post Reply