• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Trying to pull text from variable with matching string

How to I get tasker to decide which one is the variable to use in order to email the vaule of 15005K?

I am trying to pull the text from whichever variable has the matching string of *KT . In the example below the value is 15005K. My problem is the *KT string can be in the 3 (%raw213) or 4 (%raw214) position at any given time. Therefore I can't assign a specific variable when trying to pull the text.

Here are two examples of the %raw21 variable. I need the *KT value to be emailed.

KCLL 231253Z 15005K 10SM CLR 13/12 A2974 RMK AO2 SLP067 T01280117
%raw21(#?*KT) = 3
%raw213 = 15005K

KCLL 231253Z AUTO 15005K 10SM CLR 13/12 A2974 RMK AO2 SLP067 T01280117
%raw21(#?*KT) = 4
%raw214 = 15005K

ASOS Local (228)
A1: HTTP Get [ Server:Port:https://www.aviationweather.gov/metar/data?ids=KCLL&format=raw&hours=0&taf=off&layout=on&date=0 Path: Attributes: Cookies: User Agent: Timeout:10 Mime Type: Output File:Tasker/ASOS/asosget.txt Trust Any Certificate:Off ]
A2: Read File [ File:Tasker/ASOS/asosget.txt To Var:%raw ]
A3: Variable Split [ Name:%raw Splitter:<!-- Data starts here --> Delete Base:Off ]
A4: Variable Split [ Name:%raw2 Splitter:<br /> Delete Base:Off ]
A5: Variable Split [ Name:%raw21 Splitter:<!-- Data ends here --> Delete Base:Off ]
A6: Variable Search Replace [ Variable:%raw21 Search:\A\s+|\s+\z Ignore Case:Off Multi-Line:On One Match Only:Off Store Matches In: Replace Matches:On Replace With: ]
A7: [X] Flash [ Text:%raw21 Long:On ] (in this case KCLL 231253Z 15005KT 10SM CLR 13/12 A2974 RMK AO2 SLP067 T01280117)
A8: Write File [ File:Tasker/ASOS/ASOSlog.csv Text:%raw21 Append:On Add Newline:On ]
A9: Variable Split [ Name:%raw21 Splitter: Delete Base:Off ]
A10: If [ %raw21(#?*KT) > 2 ] (the value in this case is 3 as *KT in the the 3rd position)
A11: If [ %raw21(#?*KT) > 5 ] (the value in this case is 3 as *KT in the the 3rd position (same as above)
A12: Email Me Pro [ Configuration:To: me@here.com, Subject: ASOS Alert, Body: ASOS reporting winds as of %raw212. This is a daily morning notification that arrives around 6:00AM. The most recent reading is: %raw21 Timeout (Seconds):0 ] (how can I get tasker to pull the variable in the third position of %raw21 based on the %raw21(#?*KT) value instead of %raw212)(%raw212 is only correct as long as *KT is not in the 4 position)
A13: End If
A14: End If
A15: If [ %ASOSDAILY ~ 1 ]
A16: Email Me Pro [ Configuration:To: me@here.com, Subject: ASOS Daly, Body:ASOS is NOT reporting winds as of %raw2. Please confirm by calling ASOS 979-846-1708 and checking online at https://www.aviationweather.gov/metar/data?ids=KCLL&format=raw&hours=0&taf=off&layout=on&date=0 The most recent reading is: %raw21 (Seconds):0 ]
(how can I get tasker to pull the variable in the third position of %raw21 based on the %raw21(#?*KT) value instead of %raw212)(%raw212 is only correct as long as *KT is not in the 4 position (same as above))
A17: Variable Clear [ Name:%ASOSDAILY Pattern Matching:Off ]
A18: End If
A19: Delete File [ File:Tasker/ASOS/asosget.txt Shred Level:0 Use Root:Off Continue Task After Error:On ]
A20: Variable Set [ Name:%raw To:Error Recurse Variables:Off Do Maths:Off Append:Off ]
A21: Variable Set [ Name:%raw1 To:Error Recurse Variables:Off Do Maths:Off Append:Off ]
A22: Variable Set [ Name:%raw2 To:Error Recurse Variables:Off Do Maths:Off Append:Off ]
A23: Variable Set [ Name:%raw21 To:Error Recurse Variables:Off Do Maths:Off Append:Off ]
A24: Variable Set [ Name:%ASOSTASKERROR To:No Recurse Variables:Off Do Maths:Off Append:Off ]
A25: Stop [ With Error:Off Task: ]
 
I am a little lost. Can you please simplify what the objective is and your Tasker sample.

Something like ... I can have a string of ...

A A A 8 A A
or
B B 8 B B B
or
C C C C C C

I need to find the string 8 and return the position
4
3
0

... Thom
 
I figured it out last night.



The solution is to wrap the variable in parentheses

To prepare the task I

Variable Set %winds to %raw21(#?*KT) = 3​

%raw21(%winds) %raw21(3) pulls the third item from the array.


ASOS Local (228)
A1: HTTP Get [ Server:Port:https://www.aviationweather.gov/metar/data?ids=KCLL&format=raw&hours=0&taf=off&layout=on&date=0 Path: Attributes: Cookies: User Agent: Timeout:10 Mime Type: Output File:Tasker/ASOS/asosget.txt Trust Any Certificate:Off ]
A2: Read File [ File:Tasker/ASOS/asosget.txt To Var:%raw ]
A3: Variable Split [ Name:%raw Splitter:<!-- Data starts here --> Delete Base:Off ]
A4: Variable Split [ Name:%raw2 Splitter:<br /> Delete Base:Off ]
A5: Variable Split [ Name:%raw21 Splitter:<!-- Data ends here --> Delete Base:Off ]
A6: Variable Search Replace [ Variable:%raw21 Search:\A\s+|\s+\z Ignore Case:Off Multi-Line:On One Match Only:Off Store Matches In: Replace Matches:On Replace With: ]
A7: Write File [ File:Tasker/ASOS/ASOSlog.csv Text:%raw21 Append:On Add Newline:On ]
A8: [X] Variable Set [ Name:%raw21 To:KCLL 240253Z AUTO 16011KT 10SM CLR 21/16 A2964 RMK AO2 SLP035 T02060161 53020 Recurse Variables:Off Do Maths:Off Append:Off ]
A9: [X] Variable Set [ Name:%raw21 To:KCLL 240253Z 16011KT 10SM CLR 21/16 A2964 RMK AO2 SLP035 T02060161 53020 Recurse Variables:Off Do Maths:Off Append:Off ]
A10: [X] Variable Set [ Name:%raw21 To:KCLL 240253Z 10SM CLR 21/16 A2964 RMK AO2 SLP035 T02060161 53020 Recurse Variables:Off Do Maths:Off Append:Off ]
A11: [X] Variable Set [ Name:%raw21 To:KCLL 240253Z 10SM CLR 21/16 A2964 RMK AO2 SLP035 T02060161 53020 16011KT Recurse Variables:Off Do Maths:Off Append:Off ]
A12: Variable Split [ Name:%raw21 Splitter: Delete Base:Off ]
A13: Flash [ Text:%raw21(#?*KT) Long:On ]
A14: Variable Set [ Name:%winds To:%raw21(#?*KT) Recurse Variables:Off Do Maths:Off Append:Off ]
A15: If [ %raw21(#?*KT) eq 0 ]
A16: Variable Set [ Name:%nowinds To:1 Recurse Variables:Off Do Maths:Off Append:Off ]
A17: End If
A18: If [ %raw21(#?*KT) > 5 ]
A19: Variable Set [ Name:%nowinds To:1 Recurse Variables:Off Do Maths:Off Append:Off ]
A20: End If
A21: If [ %nowinds eq 1 ]
A22: Flash [ Text:No winds Long:On ]
A23: Email Me Pro [ Configuration:To: me@here.com, Subject: ASOS Alert, Body: ASOS reporting winds as of %raw21(%winds). This is a daily morning notification that arrives around 6:00AM. The most recent reading is: %raw21 Timeout (Seconds):0 ]
A24: End If
A25: If [ %ASOSDAILY ~ 1 ]
A26: Email Me Pro [ Configuration:To: me@here.com, Subject: ASOS Daly, Body: ASOS re... Timeout (Seconds):0 ]
A27: Variable Clear [ Name:%ASOSDAILY Pattern Matching:Off ]
A28: End If
A29: Delete File [ File:Tasker/ASOS/asosget.txt Shred Level:0 Use Root:Off Continue Task After Error:On ]
A30: Variable Set [ Name:%raw To:Error Recurse Variables:Off Do Maths:Off Append:Off ]
A31: Variable Set [ Name:%raw1 To:Error Recurse Variables:Off Do Maths:Off Append:Off ]
A32: Variable Set [ Name:%raw2 To:Error Recurse Variables:Off Do Maths:Off Append:Off ]
A33: Variable Set [ Name:%raw21 To:Error Recurse Variables:Off Do Maths:Off Append:Off ]
A34: Array Clear [ Variable Array:%nowinds ]
A35: Variable Set [ Name:%ASOSTASKERROR To:No Recurse Variables:Off Do Maths:Off Append:Off ]
A36: Stop [ With Error:Off Task: ]
 
Back
Top Bottom