ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Number between (1-30)

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Scott McGee
Number between (1-30)
on Jun 14, 2017 at 2:27:56 pm
Last Edited By Scott McGee on Jun 14, 2017 at 3:01:44 pm

I've got this expression.

input = thisComp.layer("^Leeds Day One").text.sourceText.toLowerCase();

if (input.indexOf("maximum temperature: 1°c") != -1) {"1"}
else if (input.indexOf("maximum temperature: 2°c") != -1) {"2"}
else if (input.indexOf("maximum temperature: 3°c") != -1) {"3"}
else if (input.indexOf("maximum temperature: 4°c") != -1) {"4"}
else if (input.indexOf("maximum temperature: 5°c") != -1) {"5"}
else if (input.indexOf("maximum temperature: 6°c") != -1) {"6"}
else if (input.indexOf("maximum temperature: 7°c") != -1) {"7"}
else if (input.indexOf("maximum temperature: 8°c") != -1) {"8"}
else if (input.indexOf("maximum temperature: 9°c") != -1) {"9"}
else if (input.indexOf("maximum temperature: 10°c") != -1) {"10"}
else if (input.indexOf("maximum temperature: 11°c") != -1) {"11"}
else if (input.indexOf("maximum temperature: 12°c") != -1) {"12"}
else if (input.indexOf("maximum temperature: 13°c") != -1) {"13"}
else if (input.indexOf("maximum temperature: 14°c") != -1) {"14"}
else if (input.indexOf("maximum temperature: 15°c") != -1) {"15"}
else if (input.indexOf("maximum temperature: 16°c") != -1) {"16"}
else if (input.indexOf("maximum temperature: 17°c") != -1) {"17"}
else if (input.indexOf("maximum temperature: 18°c") != -1) {"18"}
else if (input.indexOf("maximum temperature: 19°c") != -1) {"19"}
else if (input.indexOf("maximum temperature: 20°c") != -1) {"20"}
else if (input.indexOf("maximum temperature: 21°c") != -1) {"21"}
else if (input.indexOf("maximum temperature: 22°c") != -1) {"22"}
else if (input.indexOf("maximum temperature: 23°c") != -1) {"23"}
else if (input.indexOf("maximum temperature: 24°c") != -1) {"24"}

else {0}


I want to compress it to something more like below.

input = thisComp.layer("^Leeds Day One").text.sourceText.toLowerCase();
n = ?
if (input.indexOf("maximum temperature: "+n+"°c") != -1) {""+n+""}
else {0}


sourceText will change, so I can't use substr. So i'm using indexof and want to array or for loop n = ?

Rather than my current expression

Any ideas?


Return to posts index

Dan Ebberts
Re: Number between (1-30)
on Jun 14, 2017 at 4:05:39 pm

One way:


input = thisComp.layer("^Leeds Day One").text.sourceText.toLowerCase();
result = 0;
for (var i = 1; i <= 24; i++){
if (input.indexOf("maximum temperature: " + i + "°c") > -1){
result = i;
break;
}
}
result



Dan



Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]