mIRC Home    About    Download    Register    News    Help

Print Thread
#222968 11/07/10 03:21 AM
Joined: Sep 2007
Posts: 109
K
kwell Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Sep 2007
Posts: 109
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

kwell #222969 11/07/10 03:46 AM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
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...)

Last edited by Horstl; 11/07/10 04:22 AM.
Horstl #223341 21/07/10 11:53 AM
Joined: Sep 2007
Posts: 109
K
kwell Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Sep 2007
Posts: 109
Thanks, works perfectly!!!!


Link Copied to Clipboard