Split variable into separate words

2,815 views
Skip to first unread message

dougwzz99

unread,
Sep 26, 2012, 3:11:20 PM9/26/12
to tas...@googlegroups.com
I'm sure this should be easy but I can't figure it out...

I have a variable %var which contains:

my line of text

I want to put each word into separate variables i.e.

%var1 = my
%var2  = line
%var3 = of
%var4 = text

Each word can vary in length so I can't use Variable Section. Variable Split would seem to be the way to go, but I can't figure out how to use space as a delimiter...

TIA.

---Doug.

Unicyclist

unread,
Sep 26, 2012, 3:49:26 PM9/26/12
to tas...@googlegroups.com
The Variable Split action is defaulted to split on "space". You just leave it blank, & it will split every word into the variable array.
Set Variable "%var" to "my line of text"
Split Variable %var Splitter optional (leave this part blank) 
This will return %var1=my, %var2=line, %var3=of, %var4=text

dougwzz99

unread,
Sep 26, 2012, 4:57:58 PM9/26/12
to tas...@googlegroups.com
I thought Variable Split would work like that, but I couldn't get it to work in my testing. Must have mucked something up somewhere, I will retest.

Thanks!

dougwzz99

unread,
Sep 28, 2012, 4:40:58 AM9/28/12
to tas...@googlegroups.com
I figured out the problem...if the variable being split starts with a space then tasker sets the first split variable to space i.e. the first word ends up in the second split variable e.g.

%var is set to ' This is a string'

(ignore the quotes, note the space before This)

then after Variable Split %var

%var1 = %var1 %var2 = This %var3 = is %var4 = a %var5 = string

Maybe a bug or working as designed? Anyway now I know what's going on my task is working fine...

Pent

unread,
Sep 28, 2012, 4:45:57 AM9/28/12
to Tasker
It's just how the underlying java function works. I have no particular
opinion whether it should work like that or not so I'll just leave it.

Pent

max jones

unread,
May 8, 2020, 7:33:13 PM5/8/20
to Tasker
To: Unicyclist, thank you. I have been racking my brain over this for over a year. I worked out how to make a date variable and add/subtract days to it.  But after I did the variable convert to Seconds To Date to get the data readable I was stuck with both the date and time. All I needed was the date. I just wan'ted to say thank you. 

Dale Smith

unread,
May 9, 2020, 10:43:01 AM5/9/20
to Tasker
Probably should say thanks to Pent also. The father of Tasker. How are you Pent? Well I hope.
Reply all
Reply to author
Forward
0 new messages