Naughty Nathan Junk from the mind of a Tech Artist…

February 5, 2009

Syntax Testing

//
// removeInvalid: takes an input string and returns a valid 
// DAG name string (alpha-numerics only)
//
// $mode: 0=strip , 1=replace_
global proc string removeInvalid(string $input, int $mode)
{
	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;
}
Filed under: MEL / Maya — Naughty @ 2:47 pm

2 Comments »

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress