Replacing/removing characters in a variable?

2,038 views
Skip to first unread message

Forest Troll

unread,
Oct 12, 2011, 5:17:20 AM10/12/11
to Tasker
I extract some information from K-9 using the %EFROM variable, and
display it as a widget using Minimalistic Text. Whenever someone has a
non-english character in their name, i.e. a Norwegian character, their
name get put inside "-characters.

English characters:
%EFROM = John Smith
Non-english characters:
%EFROM = "Jøhn Smøth"

Is there some easy way to remove the character " from this variable?
I've been thinking of using split, but their sender name may contain
multiple "words" (names), wouldn't that make it complicated?

Also, if they haven't entered a sender name, %EFROM will be their
actual email-adress. I then do a split using @, to get whatever that's
before the @ as what that will be displayed on the Minimalistic Text
widget.

So, from the email steve...@apple.com, I will get
"steve.jobs" (without "-signs). However, a lot of people seem to enter
their email as Steve...@apple.com, and then I will get Steve.Jobs.
Is there a sufficient way to replace any .'s in a variable with
spaces? Here, I've also though about using split, but again, they may
have multiple names.

So, to sum up.. How can I get change variables in this way:
"any number of words" => any number of words
any.number.of.words => any number of words


Best regards

BossMan

unread,
Oct 12, 2011, 5:37:37 AM10/12/11
to tas...@googlegroups.com
How about something like this:

Variable Set %myefrom = %EFROM
Variable Split %myefrom, "  --> that's for getting rid of possible quotes
If %myefrom2 is set
Variable Set %myefrom = %myefrom2
Variable Clear %myefrom?
Endif
Variable Split %myefrom, .  --> that's for getting rid of possible dots
If %myefrom2 is set
Variable Join %myefrom, joiner = , delete parts
Endif
Flash %myefrom  --> should flash always 'any number of words'

BR,
A.

Pent

unread,
Oct 12, 2011, 6:05:59 AM10/12/11
to Tasker
Search replace is on the todo list BTW.

Pent

Forest Troll

unread,
Oct 12, 2011, 6:41:16 AM10/12/11
to Tasker
Yeah, splitting using " worked like a charm. I just recieved an email
from someone with a Norwegian character, and that made it quite easy
to work out.

If I assume that people will have max 4 names, and I then do a split
using "." and then join %EFROM12 %EFROM14 %EFROM16 and %EFROM18 if
%EFROM18 is set, join %EFROM12 %EFROM14 and %EFROM16 if %EFROM16, and
so on, then I guess I will be able to remove the .'s. I'll just wait
for an email from someone that will give a John.Johnny.Smith-variable,
and see if I can work out something using splitting and joining.

But my Tasker-profiles are getting more and more complicated, using a
lot of IF's and so on. So whenever "replace" get's possible, I guess I
can get the same results with a way more simple setup.. :)

Best regards

On the other hand; I can't get variables like %TNET and %CELLSIG to
work. They are apparently never set on my HTC Desire Z. Any ideas on
that?

BossMan

unread,
Oct 12, 2011, 7:23:27 AM10/12/11
to tas...@googlegroups.com

If I assume that people will have max 4 names, and I then do a split
using "." and then join %EFROM12 %EFROM14 %EFROM16 and %EFROM18 if
%EFROM18 is set, join %EFROM12 %EFROM14 and %EFROM16 if %EFROM16, and
so on, then I guess I will be able to remove the .'s.

But this should work already with both dots and quotes in the recipe I gave you - doesn't it? Also, your concept of getting only even members (2, 4, 6, ...) is wrong - during splitting, the splitter is removed and the "data" is put in the variables xx1, xx2, xx3 etc. (example: if you split aaaa.bb.c, you'll get var1 = aaaa, var2=bb, var3=c). Also, I suggest using local variables (hence my lower-case variable names) instead of global ones (those in UPPERCASE). 

BR,
A.

Forest Troll

unread,
Oct 12, 2011, 8:13:25 AM10/12/11
to Tasker
(What I want to "replace"/"remove" characters from are always %EFROM1,
since I first split %EFROM using < and @ with some IF's.. %EFROM is
like this, though
1) if name is given:
Name Nameson <name.n...@gmail.com>
2) if name is given, and has foreign character:
"Navn Navnesønn" <navn.na...@gmail.com>
3) if name not given:
name.n...@gmail.com)

When %EFROM1 was like
"Navn Navnesønn"
and I did a split using "
Navn Navnesønn
became %EFROM12, and not %EFROM11 - and based on that I believed that
the splitter also was assigned a number. %EFROM11 appears to be empty
in the global variable editor. But this is not a big deal, I'll figure
it out whenever I try. Now I'm just waiting an email from someone that
will give an %EFROM like alternative 3 above, since it's way easier to
do this when I can see the results "live"..

The current setup gives the wanted result for case 1 and 2 above..

What that may be useful in the future would be some kind of "make the
first letter in each word in the variable uppercase".. :P

BossMan

unread,
Oct 12, 2011, 12:50:27 PM10/12/11
to tas...@googlegroups.com
When %EFROM1 was like
"Navn Navnesønn"
and I did a split using "
Navn Navnesønn
became %EFROM12, and not %EFROM11 - and based on that I believed that
the splitter also was assigned a number. 

Wrong assumption ;) If you'd put a"b"c, you'd notice that %var1 is a, %var2 is b, and %var3 is c. The problem here is the splitter is the first character and the variable split works in such way that it puts every element, on each side of the splitter, into variables. That's why %EFROM11 is not set in your case (it's an empty string).

I made that task myself to check the idea was correct - and actually it is, with one reservation though: it seems it is not possible to use white space as a joiner (i.e. it is accepted but variables are joined together without a space as a result).

A1: Variable Set [Name:%myvar To:"test.string.with.dots.and.quotes" Do Maths:Off Append:Off]
A2: Flash [Text:Start %myvar Long:Off]
A3: Variable Split [Name:%myvar Splitter:" Delete Base:Off]
A4: If [ %myvar2 Is Set ]
A5: Variable Set [Name:%myvar To:%myvar2 Do Maths:Off Append:Off]
A6: Variable Clear [Name:%myvar? Pattern Matching:On]
A7: End If
A8: Flash [Text:myvar %myvar Long:Off]
A9: Variable Split [Name:%myvar Splitter:. Delete Base:Off]
A10: Variable Join [Name:%myvar Joiner: Delete Parts:On] Variable Join [ %myvar2 Is Set ]
A11: Flash [Text:Final %myvar Long:Off] 

BR,
A.

BossMan

unread,
Oct 13, 2011, 5:34:09 AM10/13/11
to tas...@googlegroups.com
Just got info from Pent about trimming white spaces in actions:

> the key info is that Variable Set is the only action that doesn't trim
> one of it's parameters, the value parameter.
>
> So whenever you want whitespace, use Variable Set to put it in a variable
> and use the variable where you want the whitespace.
>
> i.e. Variable Set, %whitespace, <--- there are spaces here but you can't see
> them
> Variable Join, %var, %whitespace

So, if you modify the previous task a bit (added action 0 and modified action 10), it should work the way you want:

--> A0 Variable Set %WHITESPACE To:  <- white space

A1: Variable Set [Name:%myvar To:"test.string.with.dots.and.
quotes" Do Maths:Off Append:Off]
A2: Flash [Text:Start %myvar Long:Off]
A3: Variable Split [Name:%myvar Splitter:" Delete Base:Off]
A4: If [ %myvar2 Is Set ]
A5: Variable Set [Name:%myvar To:%myvar2 Do Maths:Off Append:Off]
A6: Variable Clear [Name:%myvar? Pattern Matching:On]
A7: End If
A8: Flash [Text:myvar %myvar Long:Off]
A9: Variable Split [Name:%myvar Splitter:. Delete Base:Off]
--> A10: Variable Join [Name:%myvar Joiner: %WHITESPACE Delete Parts:On] Variable Join [ %myvar2 Is Set ]

A11: Flash [Text:Final %myvar Long:Off] 

BR,
A.

Forest Troll

unread,
Oct 24, 2011, 7:23:56 PM10/24/11
to Tasker
What about enabling space as a joiner? Or eventually enabling
something like &space; to give a space, if the actual space
character is the problem? :P
Reply all
Reply to author
Forward
0 new messages