Activity › Forums › Adobe After Effects Expressions › Comparing text with javascript
-
Comparing text with javascript
Posted by Corby Logue on January 30, 2013 at 7:08 pmScripting question
I’ve got the basics of a script to open and read an external txt file.
In the file, I’m using a dollar sign ($) to mark breaks. I’d like to be able to count the total number of these in the text using script.
So something like:
var DS = 0if [whatever script command is used to evaluate a string/word of text] == $
then DS++
How do you do this with javascript?
Thanks
Corby Logue replied 13 years, 3 months ago 2 Members · 5 Replies -
5 Replies
-
Corby Logue
January 30, 2013 at 11:10 pmSo I’ve made a little headway, or at least I understand a little better what’s going on.
I’ve got a var called myFile for the text file.
Then I create a var for the text and use ‘readIn()’. So suppose line one in my external my text document is “Once upon a time”
var text;
text = myFile.readln();if (text == "Once")
DS ++;
Nothing happens, because the text variable is assigned the value of the entire line of text (“Once upon a time”).
So is there a way to be able to check just a word or even a single character from the text value?
-
Corby Logue
January 30, 2013 at 11:25 pmYes, I am going to answer my own questions. I promise I’m googling furiously before I ask… It’s just I keep googling.
Anyway… “text.charAt(0);” is what I needed.
-
Dan Ebberts
January 30, 2013 at 11:45 pmThis would be one way to count the number of “$” characters:
text.split(“$”).length-1
Dan
-
Corby Logue
January 31, 2013 at 7:10 pmDifferent problem but same project… Not sure I understand why I’m not getting the behavior I think I should be getting:
var myComp = app.project.activeItem
var selLayers = myComp.selectedLayers;
var myMarker = selLayers[0].property("Marker");
var curMarker = myMarker.keyValue(i+1);for (i=0; i < 4; i++){
alert(i + " " + curMarker.comment);
}
Wasn’t getting what I wanted, so I set up the alert to tell me what the script was doing.
Anyway, the alert value for “i” counts up like it should (0… 1… 2… 3… ), but the comment is always the comment at the 5th marker (there is no marker 0, so I add one to it)?
Why is it not cycling through (e.g. first returning the comment at the first marker, second returning the comment at the second marker, etc.)?
-
Corby Logue
January 31, 2013 at 8:00 pmGot it… But I thought this was where I started.
Anyway, this: “var curMarker = myMarker.keyValue(i+1);”
Needs to be inside the loop. I could have sworn, that’s where I started, but I kept getting an error when running the script.
Okay… on to the next obstacle as I feel my way around in the low light!
Reply to this Discussion! Login or Sign Up