int $cur_numb = match "*[0-9]" $sel\_root[0]; // get index of selected grp
int $new_numb = $cur_numb+1;
print ($cur_numb +" and "+ $new_numb);
cccGrp_2
// Warning: line 3: Converting string "" to an int value of 0. //
0 and 1
=== that's the best I could achieve.. tried also stringArrayToString with same result or to declare $cur_numb as string -> // Error: Line 4.18: Invalid redeclaration of variable "$cur_numb" as a different type. //
You can use regular expressions or tokenizing. Turn strings to ints with something like a = (int) "12"
I dont happen to have a MEL interpreter in front of me so ill give you a python solution instead:
import re
ENDNUM = re.compile('(.*?)(\\d+$)')
def name_add1(name):
try:
pre, num = ENDNUM.findall(name)[0]
num = str(int(num)+1)
except:
pre = name
num= "_2"
return pre + num
print name_add1("name_with_digits_12")
print name_add1("somethingElse1002")
print name_add1("somethingElse")
The same outlined method would work for mel with a bit of modification in syntax.
Thank you Joojaa. Good to see a solution in Python, however I have almost no idea how to operate it. As I see from your script, then your suggestion is to stick with declaring functions (procedures) in MEL too, right? Being a rookie also in MEL, recently I run out of all "classic" ($a, $i, $j, $n, $x etc) variables, because I had them already declared not locally in expressions. But, as I see, in aferementioned case has to do something with declaring variables, its about data conversion and types in MEL, especially strings dominating over all the others.. threfore, does it mean that there is no way to extract integer variable from object's name (string)?
threfore, does it mean that there is no way to extract integer variable from object's name (string)?
No, see my comment about something like a = (int) "12". See things tend to gravitate towards strings but you can use the typecast operator (int), (float) etc. to foce it going the other way, Compare the lines: