Syntax Testing
//
// removeInvalid: takes an input string and returns a valid DAG name string (alpha-numerics only)
//
global proc string removeInvalid(string $input, int $mode) // 0=strip , 1=replace_
{
string $output = "";
for ($n = 1 ; $n < size($input)+1 ; $n++)
{
string $char = `substring $input $n $n`;
if ($n == 1 && `match "[0-9]" $char` != "")
$output += ("_"+$char);
else if (`match "[a-zA-Z0-9_]" $char` != "")
$output += $char;
else if ($mode)
$output += "_";
}
return $output;
}
This entry was posted
on Thursday, February 5th, 2009 at 2:47 pm and is filed under MEL / Maya.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
October 23rd, 2013 at 1:05 pm
I know this was posted a few years ago so you may not be keeping up with it, but I was wondering if you could query the value of a textfield, strip it of invalid characters and re-input the valid character string to the field?
October 23rd, 2013 at 8:26 pm
sure you can, it’s a piece of cake in both MEL and Python, what exactly would you like to know about doing it? email me at nathan@(this.domain) if you like and we can discuss it properly.