Imk0tter

Imk0tter

Joined
May 25, 2011

Activity Stream

Imk0tter commented on a Page, $replaceTok(string,substr,n,token)  -  May 09, 2021

$replacetok(%string,sub1, n1, token1, sub2, n2, token2, ...)

alias replacetok {
  var %string $1
  var %count 2

  while %count < $0 {

    var %replaceText [ $ $+ [ %count ] ]
    inc %count

    var %max $pos(%string,%replaceText, 0)

    var %token $parseRange([ $ $+ [ %count ] ], %max)
    inc %count

    var %startTok $token(%token,1,32)
    var %endTok $token(%token,2,32) + 1

    var %text [ $ $+ [ %count ] ]
    inc %count

    var %tokensReplaced 0

    while %startTok < %endTok {
      var %pos $pos(%string,%replaceText,$calc(%startTok - %tokensReplaced))
      var %string $+($left(%string,$calc(%pos - 1)),%text,$right(%string,- $+ $calc(%pos + $len(%replaceText) - 1)))

      inc %startTok
      inc %tokensReplaced
    }
  }
  return %string
}

alias -l parserange {
  var %input $1
  var %maxRange $2

  var %startNumber
  var %endNumber

  ;if the first character is a -, the first parameter is a negative number; proceed to second - or end of the string
  var %flag $iif($left(%input,1) == -,$true,$false)

  var %b $token(%input,1,45)

  var %input $iif(%flag,$right(%input,-1),%input)
  var %a $pos(%input,-,1)

  if %a == $len(%input) {
    ;second - as at end of string (range encountered) no second integer
    %startNumber = $iif(%flag,$calc(%maxRange - %b + 1),%b)
    %endNumber = %maxRange
  }
  else if !%a {
    ;no - after the first token; no range
    %startNumber = $iif(%flag,$calc(%maxRange - %b + 1),%b)
    %endNumber = %startNumber
  }
  else {
    ;range encountered; second number present
    var %startNumber $iif(%flag,$calc(%maxRange - %b + 1),%b)

    ;proceed to first - or end of string, and if there is a positive or negative integer

    var %a $iif($Pos(%input,-,1),$v1,0)
    var %b $iif($pos(%input,-,2),$v1,0)

    if %b > 0 && $calc(%b - %a) == 1 {
      ;second integer is negative,

      var %endNumber $calc(%maxRange - $token(%input,2,45) + 1)
    }
    else if %b == 0 {
      ;second integer is positive
      var %endnumber $token(%input,2,45)
    }
    else {
      ;unknown condition
      var %endnumber $token(%input,2,45)
    }
  }
  return %startNumber %endNumber
}
 Respond  
Imk0tter created a Page  -  May 07, 2021

Here is an alias that allows you to replace the n'th occurence of the specified substring in the specified string with a token.

  1 Thread   mIRC  
Imk0tter created a Page  -  May 06, 2021

Here is a snippit of code that allow you to get tokens from bvars (binary variables).

 Respond   mIRC  
Imk0tter commented on a Comment, mSL++  -  Aug 20, 2014
Imk0tter commented on a Comment, mSL++  -  Jul 29, 2014
Imk0tter created a mIRC Script  -  Jul 28, 2014
 Respond   mIRC  
Imk0tter commented on a Page, Least Common Multiple  -  May 28, 2011

to enhance jaytea's post:

each work with a dynamic number of parameters

alias gcd {
  while $2 {
    while $2 {
      tokenize 32 $2 $calc($1 % $2) $3-
    }
    tokenize 32 $1 $3-
  }
  return $1
}
alias lcm {
  while $2 {
    tokenize 32 $calc($1 * $2 / $gcd($1, $2)) $3-
  }
  return $1
}
 Respond  
Imk0tter commented on a mIRC Script, Connect 4  -  May 26, 2011

seems like wims from swiftirc already has that covered ;)

http://forum.swiftirc.net/viewtopic.php?f=74&t=24548

 Respond  
Imk0tter created a mIRC Script  -  May 26, 2011
Imk0tter created a mIRC Script  -  May 26, 2011
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.