PDA

View Full Version : How do I truncate a string, and keep the last value?



3dron
October 29th, 2002, 03:29 AM
I have a bunch of thumbnails created by attachMovie.

Then when you click on one, I use "this" which returns me the complete mc path to this tumbnail icon.

I only want the last part which is a number. And sometimes it is more than one character.

Example:
_level0.Stage.thumbNail12

newVar = this; (returns me the whole mc)

I want to extract the number "12" at the end, and set another variable equal to only the 12.


Does this make sense?

Ron

sbeener
October 29th, 2002, 06:36 PM
here's a prototype that will parse backwards through a movie's name, once it hits a non number character, it returns everything it's parsed. if there are no non-number characters, the whole name is returned.



MovieClip.prototype.returnNum = function(){
var s = this._name;
var i = s.length
while(i--){
if(isNaN(s.charAt(i))) break;
}
return s.substr(i+1);
}