mIRC Home    About    Download    Register    News    Help

Print Thread
#61828 26/11/03 01:00 AM
Joined: Dec 2002
Posts: 68
P
Babel fish
OP Offline
Babel fish
P
Joined: Dec 2002
Posts: 68
In 192d29h1m, how could I get the number before the d, the h and the m? Any of the numbers can change, or certain sections (e.g. '192d' or '29h') could be missing.

#61829 26/11/03 01:47 AM
Joined: Dec 2002
Posts: 417
O
Fjord artisan
Offline
Fjord artisan
O
Joined: Dec 2002
Posts: 417

$left(text,N) Returns the N left characters of text.

$right(text,N) Returns the N right characters of text.

$left(text,1-4) Returns 192d'
or '

$right(text,3-) Returns 29h




Intelligence: It's better to ask a stupid question, then to prove it by not asking....
#61830 26/11/03 02:25 AM
Joined: Dec 2002
Posts: 68
P
Babel fish
OP Offline
Babel fish
P
Joined: Dec 2002
Posts: 68
The problem with that is some numbers could be a different number of digits, so they'd return incorrect values.

#61831 26/11/03 02:57 AM
Joined: Dec 2002
Posts: 417
O
Fjord artisan
Offline
Fjord artisan
O
Joined: Dec 2002
Posts: 417
What triggers the 192d29h1m what does it refer to a Time or Location refferance?




Intelligence: It's better to ask a stupid question, then to prove it by not asking....
#61832 26/11/03 03:28 AM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
A regular expression would be a simple way to do what you want. Here's an example alias that takes the '192d29h12m'-type string as it's parameter:
Code:
moo {
  [color:red]; Call regular expression. All results will be [i]x[/i] amount of numbers ending with a single letter.[/color]
  !.echo -q $regex(parsetime, $$1, /(\d+[a-z])/gi)
  var %i = 1
  [color:red]; Loop through results of regular expression call[/color]
  while $regml(parsetime, %i) {
    [color:red]; Assign rightmost character (the letter) to %char. Assign everything else to %num.[/color]
    var %char = $right($ifmatch,1), %num = $left($ifmatch,-1)
    [color:red]; If %char is d set %num variable %days[/color]
    if (%char == d) var %days = %num
    [color:red]; Hours checking/assignment...[/color]
    elseif (%char == h) var %hours = %num
    [color:red]; Mins checking/assignment...[/color]
    elseif (%char == m) var %mins = %num
    inc %i
  }
  echo -a %days $+ days %hours $+ hours %mins $+ mins
}


Hopefully it all makes sense with the comments I've added. Of course you'll probably want more than just days, hours, and minutes, you can just add more checks in the same format as the others.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
#61833 26/11/03 03:46 AM
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
Yep, I thought about this solution too, but didn't know how to clearly state it. Btw, you can use $regml(N) to directly reference to the last $regex call without having to use "pattern names".

#61834 27/11/03 02:57 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Personally I don't like using $regml() with unnamed result sets. In many ways it's like storing the result in a global variable - any other function you call between $regex() and $regml() could potentially use a regular expression also and overwrite the results. Of course I know my example didn't use any, but since it was just a basic demonstration it will almost certainly be changed with God-knows-what put in there. Even then the chances are slim of a $regml() 'collision' but it's better to have peace of mind IMO.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
#61835 28/11/03 01:26 AM
Joined: Aug 2003
Posts: 1,831
I
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
Might be simpler to use $duration()
Code:
mootoo {
  var %a = $$1
  !.echo -q $regsub(%a,/(\d+[a-z])/gi,\1 $chr(32),%a)
  echo -a $duration($duration(%a))
}

#61836 28/11/03 10:12 AM
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
Sounds reasonable. I might start to use pattern names in demonstration scripts too.


Link Copied to Clipboard