|
pouncer
|
pouncer
|
alias _Tokenize {
var %x = 1
while (%x <= $numtok($1-,32)) {
var %y = %y $+(04[01,%x,04,$chr(44),01,$gettok($1-,%x,32),04])
inc %x
}
echo -s %y
}
Is there a way i can make that smaller perhaps using a regsubex guys?
|
|
|
|
Joined: Mar 2003
Posts: 611
Fjord artisan
|
Fjord artisan
Joined: Mar 2003
Posts: 611 |
$numtok($1-,32) can be replaced with $0
billythekid
|
|
|
|
Joined: Feb 2005
Posts: 342
Fjord artisan
|
Fjord artisan
Joined: Feb 2005
Posts: 342 |
Sure. alias _tokenize { echo -s $regsubex($1-,/(\S+)/g,$+(04[01,\n,04,$chr(44),01,\t,04])) }
|
|
|
|
TropNul
|
TropNul
|
If I correctly understood the objective, here's what can replace it.
Alias _Tokenize { Echo -s $regsubex($1-,/(\S+)/g,$+(04[01,\n,04,$chr(44),01,\1,04])) }
Explanations: Pattern: /(\S+)/g means " unless a space is matched, continue to match " . So this method will locate one after the other, each word of the string.
|
|
|
|
Joined: Oct 2006
Posts: 166
Vogon poet
|
Vogon poet
Joined: Oct 2006
Posts: 166 |
Here's another method:
[code]alias _tokenize tokenize 32 $1 | scon -r var $(%b = %b ,) $!+(4[,$calc( $!numtok(%b,32) +1),4,$chr(44),, $* ,4]) | return %bn %b % [/code]
|
|
|
|
Joined: Sep 2005
Posts: 2,630
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,630 |
alias _Tokenize { echo -s $regsubex($1-,/([^ ]+)/g,$+(04[01\n04,$chr(44),01\t04])) }
|
|
|
|
Joined: Apr 2004
Posts: 700
Hoopy frood
|
Hoopy frood
Joined: Apr 2004
Posts: 700 |
Never use that method unless you know exactly what the input will be. It will double-evaluate the contents of $1-, so if there's external input on there, you open up a huge security hole. Try "//echo -ag $_tokenize($!pi)" if you don't believe me.
Saturn, QuakeNet staff
|
|
|
|
Joined: Oct 2006
Posts: 166
Vogon poet
|
Vogon poet
Joined: Oct 2006
Posts: 166 |
Thanks. it depends on what you are trying to pass with the identifier. I just posted that for fun tbh
|
|
|
|
Joined: Oct 2006
Posts: 166
Vogon poet
|
Vogon poet
Joined: Oct 2006
Posts: 166 |
|
|
|
|
Joined: Jan 2003
Posts: 2,125
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,125 |
\S matches any char except 'whitespace'. This term however includes not only normal spaces (char 32) but also tabs, cr, lf etc. Those are not displayed as spaces in mirc windows.
|
|
|
|
Joined: Sep 2005
Posts: 2,630
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,630 |
The other change I made is that you do not need to use $+ to separate \t and \n from other text in the replacement parameter of $regsubex.
|
|
|
|
Joined: Oct 2006
Posts: 166
Vogon poet
|
Vogon poet
Joined: Oct 2006
Posts: 166 |
|
|
|
|
|