LC #42 Pipers Alley

View Full Version : How do I truncate a string?

05-03-2009, 02:34 AM
Say I have created an object in my scene called $Object1_Ref, and I want to use MaxScript to create a copy of it simply called $Object1. (In actuality, I will be doing this for more than one object, or I wouldn't really need a script). I've gone through the help files looking for information on how to work with strings, but can't find what I am looking for. I basically just want something that works like the "Remove Last: (x) Digits" in the rename objects tool.

05-03-2009, 02:59 AM
theString = $

theCopy = copy $object_ref = (filterString theString "_" )[1]


trimRight theString "_ref"

and replace

05-03-2009, 03:07 AM
Substring would probably be the easiest route. From there you would simply make the substring length = to the current string count - the trim amount. Something like this would do it:trim = 4
obj = $Object01_Ref
objNm = substring 1 ( = objNmPlace that inside an array loop and your all done.

Hope that helps,

05-03-2009, 03:36 AM
Thanks so much for the quick responses!

CGTalk Moderation
05-03-2009, 03:36 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.