mIRC Homepage
Posted By: Thray Tokenizing, Real Weird-like - 27/09/03 07:04 PM
Theres something I'm trying to do, but can't seem to get it done. Basically, I have a command with the following syntax:
@Start T=RT R=Room U=Chaz, Ranma, Thray M=Multiple Word String, MPS, Etc Etc

Then I split up the info into variables. %t = RT, %r = Room, %u = Chaz.Ranma.Thray, etc. (It changes ", " to . beforehand so Multiple Word String, MPS becomes Multiple Word String.MPS and so on)

Now here is the challenge.. I want to get all the words from M= into a string of .s.. %m = Multiple Word String.MPS.Etc Etc Like that. But I want the user to be able to put m= in any place. So.. .the command could also look like:

@Start M=Multiple Word String, MPS, Etc Etc T=RT R=Room U=Chaz, Ranma, Thray

And so on. The problem above is that I keep getting the entire string in that case.

var %com = $replace($4-,$+($chr(44),$chr(32)),.,$chr(44),.)
var %t = $remove($wildtok(%com,t=*,1,32),t=)
var %r = $remove($wildtok(%com,r=*,1,32),r=)
var %u = $remove($wildtok(%com,u=*,1,32),u=)

Thats what I used to get the info.



Any help?
Posted By: Sigh Re: Tokenizing, Real Weird-like - 27/09/03 10:35 PM
You can use:

% $+ $replace($replace(command,$chr(44) $+ $chr(32),$chr(46)),$chr(32),$chr(32) $+ %))

Which will turn, for example:

1=a, b, c 2=d, e, f 3=g, h, i

Into:

%1=a.b.c %2=d.e.f %3=g.h.i

You could then loop through $numtok(that,32) and set each variable ($gettok($gettok(that,n,32),1,61)) to the value on the other side of the equals sign ($gettok($gettok(that,n,32),2,61))
Posted By: BlackAle Re: Tokenizing, Real Weird-like - 28/09/03 11:42 AM
You can also use...

Code:
if $regex(%com, /(?i)^@start(?=.*M=(.*?)(?:\w=|$)|())(?=.*R=(.*?)(?:\w=|$)|())(?=.*T=(.*?)(?:\w=|$)|())(?=.*U=(.*?)(?:\w=|$)|())/) {
   var %m = $regml(1)
   var %r = $regml(2)
   var %t = $regml(3)
   var %u = $regml(4)
}


That'll work no matter what order the parameters M, R, T, U are in, it will also work if any parameters are obmitted.
Posted By: cold Re: Tokenizing, Real Weird-like - 29/09/03 12:42 AM
This won't work with multiple word values.
Posted By: BlackAle Re: Tokenizing, Real Weird-like - 29/09/03 03:12 AM
? ...works here.
Posted By: cold Re: Tokenizing, Real Weird-like - 29/09/03 03:18 AM
That was a reply to Sigh and his $replace() method. Yours works.
© mIRC Discussion Forums