PDA

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


eYadNesS
01-06-2011, 07: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.

haggi
01-06-2011, 08: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"`;

eYadNesS
01-06-2011, 08:59 AM
Thank you a lot, thats exactly what i'm looking for.

CGTalk Moderation
01-06-2011, 08: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.