mIRC Homepage
Posted By: earthquake looking for a function/identifier - 23/02/03 07:51 AM
Is there a function/identifier that specifically reverse all letters, including spaces, for every sentence? If so, please tell me what it is as I can't seem to find it in the mirc help file.

Thanks,
EQ
Posted By: Collective Re: looking for a function/identifier - 23/02/03 08:00 AM
Code:
alias reverse {
  var %c = $len($1)
  while ( %c ) {
    if ( $asc($mid($1,%c,1)) != 32 ) {
      var %r = %r $+ $mid($1,%c,1)
    }
    else {
      dec %c
      var %r = %r $mid($1,%c,1)
    }
    dec %c
  }
  return %r
}

Stick that in your remotes and type //echo -a $reverse(text), it should give you "txet".
Posted By: earthquake Re: looking for a function/identifier - 23/02/03 08:40 AM
Thanks for the help.. May I ask you to please explain this piece of code from while %c part down =)
Posted By: Collective Re: looking for a function/identifier - 23/02/03 10:11 AM
I would explain it, but after 3 attempts at trying I've pretty much given up, but in brief:
1. It sets %c to the length of $1-
2. It checks to see if %c has a value that isn't 0, $null, or $false, if it does have one of those values, it goes to #5.
3. It takes the character in postion %c of $1- and adds it to the end of %r (which at the start of the script is not set, btw).
4. It decreases %c and goes back to #2.
5. It returns the value of %r

The reason for the 2 IFs inside the while loop is because of a limitation with mIRC to do with spaces, which I'm too lazy/stupid to explain smile.
Posted By: Hammer Re: looking for a function/identifier - 23/02/03 10:16 AM
Just had to put my 2 cents in.
Code:

alias reverse {
 
  var %1- = $replace($$1-, $chr(32), $chr(127))  | ; Input string (spaces excepted)
  var %string                                    | ; Output string
  var %i = 1                                     | ; Loop index to go character by character through the string
 
  while $mid(%1-, %i, 1) {                       | ; While there are more letters in the input string
    %string = $ifmatch $+ %string                | ; Add the current letter to the beginning of the string
    inc %i                                       | ; Go to the next letter
  }
 
  return $replace(%string, $chr(127), $chr(32))  | ; Replace the spaces in the output string and pass it back
 
}

//echo $color(info) -abflirt * $reverse(This is a long string to try this out on)
* no tuo siht yrt ot gnirts gnol a si sihT
Posted By: Collective Re: looking for a function/identifier - 23/02/03 10:18 AM
Upstaged again! *shoots himself*...I'll find a bug in it, you just wait mad
Posted By: Hammer Re: looking for a function/identifier - 23/02/03 10:34 AM
Feel completely free to shoot any holes you can ever find in any script or script segment you ever see from me. I really do welcome that kind of criticism; I learn from it or perhaps clarify it the way I should have done before I posted it. I learn from code posted here regularly...my own code, included.

There is nothing wrong with yours, per se. I just would have done it in a slightly different manner, which is what I posted. I did not mean to upstage you in any way. If I did, I apologize.
Posted By: Collective Re: looking for a function/identifier - 23/02/03 10:34 AM
lol, I was taking the piss actually, didn't think you'd take it seriously smile
Posted By: Hammer Re: looking for a function/identifier - 23/02/03 10:36 AM
I thought you might be :tongue: but I meant it about shooting holes in my scripting. That goes for anyone who can find those holes, as well.
© mIRC Discussion Forums