RealTokenize MEL

From scripting
Jump to: navigation, search

Just a note, the MEL tokenize will split up a string, but it will not remember empty strings. Empty strings are ignored. My "RealTokenize" subroutine will split any string with a one-character delimiter and remember empty strings.

global proc string[] RealTokenize(string $CurStr, string $Delim) {
	//Author: Nick Pisca 2010 0001d
	//string $CurStr = "d,s,d,s,,,,e"; string $Delim = ",";
	//RealTokenize "d,s,d,,,e,e" ",";
	string $PartString;
	string $TempArr[];
	int $t = 0;
	for ($x=1;$x<size($CurStr)+1;$x++) {
		string $CurLetter = `substring $CurStr $x $x`;
		if ($CurLetter == $Delim) {
			$TempArr[$t] = $PartString;
			$PartString = "";
		} else {
			$PartString = $PartString + $CurLetter;
       $TempArr[$t] = $PartString;
	return $TempArr;

More information on strings and arrays, read pages 28-37 in YSYT.