split based on string in maya (mel)
Default tokenize in Maya accepts the source string and split character as arguments. It wont accept a
string as the second parameter. This splitString() takes two strings as input arguments.
[cpp]
global proc string[] splitString(string $source, string $splitter)
{
int $sourcelen,$splitterlength,$i,$beg_mat[],$beg_index=0,$j,$k=0,$start=1;
string $out[];
$sourcelen = size($source);
$splitterlen = size($splitter);
if($splitterlen != 0)
{
for($i=1;$i<=$sourcelen-$splitterlen+1;++$i)
{
if(`substring $source $i ($i+$splitterlen-1)` == `substring $splitter 1 $splitterlen`)
{
$beg_mat[$beg_index++] = $i;
$i = $i + $splitterlen - 1;
}
}
$beg_mat[$beg_index++] = $sourcelen + 1;
for($i in $beg_mat)
{
$j = $i - 1;
if($start <= $j)
{
$out[$k++] = `substring $source $start $j`;
}
$start = $i + $splitterlen;
}
}
return $out;
}
splitString("abcdeabcdab","abc");
[/cpp]