mIRC Homepage

$movetok() + $movetokcs()

Posted By: DooMaster

$movetok() + $movetokcs() - 08/02/21 07:41 PM

Hello sick

I wanna suggest a new identifier to be able to move an old string position item into an new position on the text.

Usage: $movetok(text,string,new-position,character)
Example: $movetok(one three two,two,2,32) = one two three

Note: Also $movetokcs() for case-sensitive usage.

- Thanks!
Posted By: Raccoon

Re: $movetok() + $movetokcs() - 09/02/21 05:51 PM

The trouble I see here, from a purely functional standpoint, is that your suggestion only represents one of the several ways that $*tok functions work. It compliments the "matching string" methods of $findtok(), $istok(), $matchtok(), $remtok() and $reptok(), but it doesn't do anything for the "matching index" methods of $deltok(), $gettok(), $instok(), $puttok()... nor does it support the wildcard matching of $wildtok().

Of course, it goes without saying that your $movtok() functionality can be solved by combining only two of the aforementioned identifiers.

Code
; $movetok(one three two, two, 1, 2, 32)
; $movetok(text, token, N, M, C)
ALIAS movtok { return $instok($remtok($1,$2,$3,$5),$2,$4,$5) }
ALIAS movtokcs { return $instokcs($remtokcs($1,$2,$3,$5),$2,$4,$5) }

The N parameter is used to specify which occurrence of the matching token to work on.
see /help $remtok().
Posted By: DooMaster

Re: $movetok() + $movetokcs() - 09/02/21 08:33 PM

So a new IRC comment (thx Talon) about that post idea came out, so the question about this is.. what if 2 same or more strings exists on text parameter..
And the answer is it can to work as $remtok() identifier, i will provide new examples.

Usage: $movetok(text,string,N,[N],C)

text == The original text
string == The match token on text value
N == The N position on text value
[N] == Optional, If N = 0, applies to all matching items (same as $remtok() identifier)
C = The C parameter is the ascii value of the character separating the tokens.

Examples: $movetok(one three two,two,2,32) == one two three || $movetok(one three two four two,two,2,0,32) == one two two three four
Posted By: maroon

Re: $movetok() + $movetokcs() - 09/02/21 08:40 PM

Fleshing this out a little more, I'm assuming that if the '2' exceeded the number of tokens in TEXT that it should move to be the final token.
And using -1 would move it to be the final position, -2 moves to be the next-to-last token, etc.
If STRING is not within TEXT, then it returns the unaltered string.
© 2021 mIRC Discussion Forums