Having Some Troubles With RemoveField

edited August 2009 in Mods and Customization
So the removeField command is supposed to remove a single field out of a tab seperated list, correct? I'm having some weird instances of it leaving some text behind.

For instance...
$test = "g1\tg2";
 g1	1

So it removes g2... but what's with that extra TAB and 1 at the end?

Any assistance would be much appreciated.

EDIT: Looks like removeWord does the same thing... Odd.
 g1	1

I should also note that removing the first field rather than the second seems to work fine.


  • edited August 2009
    Krash and nil both supplied me with a re-writes of this function that can be found at the following URLs.

    function removeField(%list,%index) {
        %count = getFieldCount(%list);
        if (%index == 0) %result = getFields(%list,1,%count);
        else if (%index == %count-1) %result = getFields(%list,0,%index-1);
        else if (%index >= %count) %result = %list;
        else %result = getFields(%list,0,%index-1) TAB getFields(%list,%index+1,%count);
        return %result;

    function removeToken(%string, %token, %index)
    	%str = "";
    	for (%i = 0; %i < %index && %string !$= ""; %i++)
    		%string = nextToken(%string, "temp", %token);
    		if (%i == 0)
    			%str = %temp;
    			%str = %str @ %token @ %temp;
    	%string = nextToken(%string, "temp", %token);
    	if (%string !$= "")
    		%str = %str @ (%index == 0 ? "" : %token) @ %string;
    	return %str;

    Preserved for posterity.
Sign In or Register to comment.