need help regarding concat function

Post your questions and help other users.

Moderator: Martin

Post Reply
houdinix64
Posts: 33
Joined: 08 Mar 2013 12:45

need help regarding concat function

Post by houdinix64 » 17 Aug 2017 09:03

Hi guys I need your help please.

my script:

smartStates = newList("Smart Rotate","Smart Timeout","Smart Notification");


for (smartState in smartStates)
{

if( contains(smartState,'Rotate' )==true )
{
detail = "on"
}

if( contains(smartState,'Timeout' )==true )
{
detail = "1 minute"
}

if( contains(smartState,'Notification' )==true )
{
detail = "active"
}

smartDetails = concat(smartState, ' (', detail, ')');

}

// string result be in this kind of format

Smart Rotate (on)
Smart Timeout (1minute)
Smart Notification (active)

Thanks....

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

Re: need help regarding concat function

Post by Desmanto » 17 Aug 2017 10:37

I am confused what you want to do. If "Smart Rotate" always have the value (on), then why don't just put the value "Smart Rotate (on)" directly? Same for other value.
You can combine them later, using join() and newline
text = join(smartStates, "\n")
Then display it (such as in notification on screen) as {text}

When using loop, it is better to use new variable which is completely different to avoid confusion. I am confused until I realize there is no 's' in the for. Better use
for ( i in smarStates)
Then use i in the loop, save your code, save your typing and avoid confusion.

contains() will always result in true or false, so no need additional "== true" in if()
Since the value comes in pair, maybe you should use map() instead. There is action map values you can use, or map function as well.
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.

houdinix64
Posts: 33
Joined: 08 Mar 2013 12:45

Re: need help regarding concat function

Post by houdinix64 » 18 Aug 2017 06:25

Thanks Desmanto for your help and tips in creating scripts. Your idea perfectly work on my flow. Thanks again

Post Reply