Trim Variable

1,826 views
Skip to first unread message

Cindy

unread,
Oct 5, 2012, 11:33:07 AM10/5/12
to tas...@googlegroups.com
I was looking through previous posts for an easy way to trim white spaces from variables. All solutions were too complex!!!! I tried the following and it worked. 

Variable -> Variable Search Replace. Use the following parameters:
  • Variable name: what to trim 
  • Search: regex value "\s+\z" (find white spaces starting at the end of a string)
  • Multi-Line: check
  • Replaces Matches: check 
  • Replace With: leave empty
  • DONE
Please let me know if there is something easier.

Cindy

easiuser

unread,
Oct 5, 2012, 12:20:36 PM10/5/12
to tas...@googlegroups.com
Should be able to do it with two actions, Split and Join.
 
Split the variable without defining a splitter
Join the array back together without defining a joiner
 
Spaces should be gone.

Cindy

unread,
Oct 5, 2012, 2:10:27 PM10/5/12
to tas...@googlegroups.com
Thanks for the help! That sounds like the inclusion of an array with 2 steps: (1) split and (2) join. My solution works against the original variable and has 1 step: Search and Replace. Please let me know how a 2 step solution is easier;)

Thanks,
Cindy

easiuser

unread,
Oct 5, 2012, 2:27:38 PM10/5/12
to tas...@googlegroups.com
Your correct, two steps but....I don't use regex enough to remember all the options and syntax and Tasker does all the array stuff with you just entering your "what to trim" variable. 
 
Maybe not easier but certianly not a "too complex!!!!" solution. :-)

Cindy

unread,
Oct 5, 2012, 5:52:06 PM10/5/12
to tas...@googlegroups.com
Thanks for the clarification easiuser. You rock!

Cindy

unread,
Oct 3, 2013, 4:24:00 PM10/3/13
to tas...@googlegroups.com
Update - Use "\A\s+|\s+\z" to trim the beginning and end of a string. 

Ruslan Alcotana

unread,
Mar 25, 2015, 10:31:19 AM3/25/15
to tas...@googlegroups.com
You can also use javaScript function trim(), but it has 1 second delay, so I prefer regexp replace. Anyway, Action->Code->javaScriptlet code: var=var.trim(), where has is your tasker variable without %.
Reply all
Reply to author
Forward
0 new messages