# How do I truncate a string, and keep the last value?

**URL:** <https://forum.kirupa.com/t/how-do-i-truncate-a-string-and-keep-the-last-value/7356>\
**Category:** flash\
**Created:** [October 29, 2002, 8:29am UTC](https://forum.kirupa.com/t/how-do-i-truncate-a-string-and-keep-the-last-value/7356 "2002-10-29T08:29:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![3dron](https://avatars.discourse-cdn.com/v4/letter/3/2acd7d/32.png) [@3dron](https://forum.kirupa.com/u/3dron)\
**Post date:** [October 29, 2002, 8:29am UTC](https://forum.kirupa.com/t/how-do-i-truncate-a-string-and-keep-the-last-value/7356/1 "2002-10-29T08:29:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 29, 2002, 11:36pm UTC](https://forum.kirupa.com/t/how-do-i-truncate-a-string-and-keep-the-last-value/7356/2 "2002-10-29T23:36:34Z")

</div>

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.

```auto

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);
}

```
