View Full Version : How to replace a word in a string?

01 January 2011, 08:06 AM
Sorry, I'm beginner with mel scripting, any one could help me on writing the following script:

I have about 20 curve controls, I want if I select "leftLegControl" and press a button, its select "leftLegControl" + "rightLegControl"...

How I can change my string "leftLegControl" to "rightLegControl", I just want to replace left with right, or right with left, depends on what i select. And if there is no left or right in the string, do nothing.

Thank you in advance.

01 January 2011, 09:30 AM
I'd suggest if you are new, avoid mel, to python. There you can simply do:

s = "leftLeg"
s.replace("left", "right")

But if you want to stay with mel, you can try the "substitute" command.

string $leg = "leftLeg";
$leg = `substitute "left" $leg "right"`;

01 January 2011, 09:59 AM
Thank you a lot, thats exactly what i'm looking for.

CGTalk Moderation
01 January 2011, 09:59 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.