mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2003
Posts: 3
E
Self-satisified door
OP Offline
Self-satisified door
E
Joined: Feb 2003
Posts: 3
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

Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
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".

Joined: Feb 2003
Posts: 3
E
Self-satisified door
OP Offline
Self-satisified door
E
Joined: Feb 2003
Posts: 3
Thanks for the help.. May I ask you to please explain this piece of code from while %c part down =)

Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
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.

Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
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


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
Upstaged again! *shoots himself*...I'll find a bug in it, you just wait mad

Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
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.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
lol, I was taking the piss actually, didn't think you'd take it seriously smile

Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
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.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C

Link Copied to Clipboard