-
How isolate numbers in Comp names and parse them into integers
In order to create a practical slide presentation template, I’m trying to get the name of each comp to be able to produce the number of the present slide within that same comp.
Each comp to which I refer is called “Slide x“, x being 1, 2, 3, etc. Inside the comp there’s an empty text layer where the slide number should appear. Now, I’ve gotten as far as obtaining the number by getting the name of the comp and then splitting it at the space, and holding the number value, which is after that space:
name = thisComp.name.split(" ")[1];
This works. But in order to make the design a little nicer, more slide-ier, I want to show the slide numbers as 001, 002, 003, etc., emulating the codes that old slides used to have. In order to do this, I’m trying to parse that number value as an integer so that I can use an if() statement that’ll add “00” or “0” according to how many digits the number retrieved has (otherwise, it’ll be something like 008, 009, 0010, 0011… which doesn’t look good).
And here’s where I’m hitting my head against a wall. I’ve looked all over, and even in the CCow forum all I can find is hot to parse from a text field into an integer, i.e. using parseInt(), which doesn’t seem to work when the value in question is gotten from another source, in this case, the name of the comp itself… I’ve also tried other things and keep on getting “NaN” as a result.So what am I doing wrong? How can I convert that number into an integer so that I can complete the expression I’m looking for?
Thanks in advance for any input you can give me!