mIRC Homepage
Posted By: kwell Replace words - 11/07/10 03:21 AM
In what way can it devise a code to replace the longest word in a sentence with a symbol "-" and place it at the end of the same
Example
Code:
“You receive certain percentage on gold stored in the Capital”

Result
Code:
“You receive certain ---------- on gold stored in the Capital”©percentage


Saludos
Posted By: Horstl Re: Replace words - 11/07/10 03:46 AM
Code:
alias replongest {
  var %n = 1, %top = 0, %tok
  while ($gettok($1-,%n,32) != $null) {
    if ($len($v1) > %top) { var %top = $v1, %tok = %n }
    inc %n
  }
  return $$puttok($1-,$str(-,%top),%tok,32) $+ @ $+ $gettok($1-,%tok,32)
}
//echo -a $replongest(“You receive certain percentage on gold stored in the Capital”)


or
Code:
alias replongest {
  var %t = $regsubex($1-,/[[:punct:]]/g,$chr(1)), %n = 1, %top = 0
  while ($gettok(%t,%n,32) != $null) {
    if ($len($remove($v1,$chr(1))) > %top) { var %top = $v1, %tok = %n, %word = $gettok($1-,%n,32) }
    inc %n
  }
  return $$puttok($1-,$regsubex(%word,/[^[:punct:]]/g,-),%tok,32) $+ @ $+ $regsubex(%word,/[[:punct:]]/g,$null)
}
//var %text = Another one, not replacing punctuation! | echo -a $replongest(%text)
(I guess this one could be shortened though...)
Posted By: kwell Re: Replace words - 21/07/10 11:53 AM
Thanks, works perfectly!!!!
© mIRC Discussion Forums