mIRC Home    About    Download    Register    News    Help

Print Thread
#179896 30/06/07 12:12 AM
P
pouncer
pouncer
P
Code:
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?

#179899 30/06/07 12:55 AM
Joined: Mar 2003
Posts: 611
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Mar 2003
Posts: 611
$numtok($1-,32) can be replaced with $0


billythekid
#179903 30/06/07 03:14 AM
Joined: Feb 2005
Posts: 342
R
Fjord artisan
Offline
Fjord artisan
R
Joined: Feb 2005
Posts: 342
Sure.

Code:
alias _tokenize { echo -s $regsubex($1-,/(\S+)/g,$+(04[01,\n,04,$chr(44),01,\t,04])) }

#179927 30/06/07 12:41 PM
T
TropNul
TropNul
T
If I correctly understood the objective, here's what can replace it.

Code:

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.


#179937 30/06/07 03:18 PM
Joined: Oct 2006
Posts: 166
B
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2006
Posts: 166
Here's another method:
Code:
[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]

#179938 30/06/07 03:36 PM
Joined: Sep 2005
Posts: 2,630
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,630
Code:
alias _Tokenize { echo -s $regsubex($1-,/([^ ]+)/g,$+(04[01\n04,$chr(44),01\t04])) }

b1ink #179939 30/06/07 03:53 PM
Joined: Apr 2004
Posts: 700
Sat Offline
Hoopy frood
Offline
Hoopy frood
Joined: Apr 2004
Posts: 700
Quote:
scon -r .. $* ..

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
Sat #179941 30/06/07 04:47 PM
Joined: Oct 2006
Posts: 166
B
Vogon poet
Offline
Vogon poet
B
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

hixxy #179942 30/06/07 04:48 PM
Joined: Oct 2006
Posts: 166
B
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2006
Posts: 166
why not \S :P

b1ink #179943 30/06/07 04:53 PM
Joined: Jan 2003
Posts: 2,125
Q
Hoopy frood
Offline
Hoopy frood
Q
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.

b1ink #179944 30/06/07 05:28 PM
Joined: Sep 2005
Posts: 2,630
H
Hoopy frood
Offline
Hoopy frood
H
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.

hixxy #180004 02/07/07 05:36 AM
Joined: Oct 2006
Posts: 166
B
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2006
Posts: 166
mm nice


Link Copied to Clipboard