PDA

View Full Version : string replacement question


thematt
03-22-2006, 01:48 PM
Hi all,
my brain is going very slow today and I can't figure an easy way of doing that simple thing.
I need to replace part of the string that contain multiple the same letter or symbol.
Here is what i need as an example.

I have something like
myobject_prop_Anim_translateX and want to replace it by myobject_prop_Anim.translateX

it simply to reconnect animcurves that are name toward what they were connected too, but I need to replace the last "_" and only this one by a "."

any help will be very appreciate.

cheers

A_New_Hope
03-22-2006, 02:39 PM
here is something to start from :)



string $CurrentName = "myobject_prop_Anim_translateX";

string $AttrName = `match "[^_]*$" $CurrentName`;
// Result: translateX //

string $NewName = `substitute "[^_]*$" $CurrentName ""`;
// Result: myobject_prop_Anim //

string $NewName = $NewName+"."+$AttrName;
// Result: myobject_prop_Anim.translateX //



for more info about about matching and extracting stuff from strings
check out Bryan Ewert site http://www.ewertb.com/maya/

thematt
03-22-2006, 04:33 PM
thanks..I had a solution working, but not as elegant as this one.
Thanks I really have to look closer to the match command..I don't know why but i can't seem to remember how it works everytime I use it.

cheers

CGTalk Moderation
03-22-2006, 04:33 PM
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.