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:
string $tr = "12";
print ($tr + 1 + "\n");
print ((int)$tr +1 + "\n");
Therefore corresponding mel code becomes (mel has no try):
global proc string name_add1(string $name){
string $end = match("[0-9]*$", $name);
string $start = substring($name,1, size($name) - size($end));
if ($end == ""){
$start = $start+"_";
$end = "1";
}
return $start+((int)$end+1);
}
print (name_add1("name_with_digits_12")+"\n");
print (name_add1("somethingElse1002")+"\n");
print (name_add1("somethingElse")+"\n");