delete first character in a variable MEL


#1

Hi
I just want to delete the first character in a variable.
as in:

$variable = “l_arm_joint”;
to
$newVariable = “_arm_joint”;

I’m running a for loop on about 50 joints so I can’t select each name and change it.
Pls help!


#2

$variable = substring $variable 2 size($variable);

In Python it’s much simpler

mystring = ‘whatever’
mystring = mystring[:-1]


#3

To avoid confusion for someone learning from these examples I’ll point out that Panupat’s python example removes the last character not the first. To remove the first character.\

s = ‘whatever’
s[1:]

Result: ‘hatever’

David


#4

o_O Can’t believe I made such easy mistake.


#5

Although I would strongly suggest you to learn Python instead, if you really have to do it in mel:

$variable = "l_arm_joint";
$newVariable = `substring $variable 2 (size($variable))`;
print $newVariable;

For those things you’ll need to use substring and/or tokenize.
And when using substring you’ll need to specify the last character using size.

BTW, in Python the equivalent of size() is len() but in Python you can specify only the first character and Python will assume the last digit. That’s why djx used [1:] instead of [1:len(s)], the result would be the same.


#6

Awesome, Thanks guys

I really got stuck into mel, much more so than I could get into python.