mIRC Home    About    Download    Register    News    Help

Print Thread
text backwards #256052 14/12/15 06:13 PM
Joined: May 2014
Posts: 35
P
Perl Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: May 2014
Posts: 35
Hello, you can tell me, if it is possible to turn a string. for example in uppercase lowercase left and right I know, but I am looking for a handle that allows me to read upside down. for example:

$get...(Hello)
with result: olleH

it's posible?? . greetings and sorry for my bad English

Re: text backwards [Re: Perl] #256053 14/12/15 06:36 PM
Joined: Dec 2015
Posts: 146
Dazuz Offline
Vogon poet
Offline
Vogon poet
Joined: Dec 2015
Posts: 146
There is probably some better way to do it, but this works too:
Code:
alias reverse var %x = 1,%r | while ($mid($1,%x,1) != $null) { var %r = $+($v1,%r) | inc %x } | return %r


Use as: $reverse(Hello world!)


EDIT:
Even better and faster alternative:
Code:
alias reverse return $regsubex($1,/(.)/g,$mid(\A,-\n,1))

Last edited by Dazuz; 14/12/15 06:44 PM. Reason: Another brain fart.
Re: text backwards [Re: Dazuz] #256055 14/12/15 10:03 PM
Joined: May 2014
Posts: 35
P
Perl Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: May 2014
Posts: 35
Dazuz you're a machine!! the only problem I see is the text that leads commas, which cuts right where they are. Thank you!! $reverse(hello, my name) -> olleh
I will try to fix it !!
thank iu!!

Re: text backwards [Re: Perl] #256056 14/12/15 10:15 PM
Joined: Apr 2010
Posts: 958
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 958
store the text in a variable prior to calling the alias:
Code:
var %input = hello, my name is jim
echo -a $reverse(%input)


I am SReject
My Stuff
Re: text backwards [Re: FroggieDaFrog] #256073 16/12/15 09:23 AM
Joined: May 2014
Posts: 35
P
Perl Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: May 2014
Posts: 35
Now if it works, greetings and thank you very much.

Re: text backwards [Re: Dazuz] #256074 16/12/15 04:04 PM
Joined: May 2014
Posts: 35
P
Perl Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: May 2014
Posts: 35
also it seems to have tried putting $1- , and it seems that also works unused variable.


Quote:
alias reverse return $regsubex($1-,/(.)/g,$mid(\A,-\n,1))


but I think your choice is better, thanks

by the way, I'm trying to understand the code and see very complex, I will have to study it calmly. Cheers

Last edited by Perl; 16/12/15 04:12 PM.
Re: text backwards [Re: Perl] #256075 16/12/15 04:45 PM
Joined: Dec 2015
Posts: 146
Dazuz Offline
Vogon poet
Offline
Vogon poet
Joined: Dec 2015
Posts: 146
The commas separate the input into different parts in identifiers. With $1- it'll read all the parts, but the commas will also be removed, since they're considered separators.

The commas are only a problem if you define the input manually, i.e. $reverse(Hello, world and, stuff!), so using the identifier in text event/alias/whatever where the input comes from the user/whatever, i.e. $reverse($1-) or $reverse(%variable), won't be a problem.

The $regsubex version works pretty much exactly the same as the while loop one, except it's more efficient. It's probably easier to break the while loop one into parts and study it, you'll get the same result, except it's probably easier to understand, tweak and play around with.


EDIT:
I'm bored, so:
Code:
;Start of the alias called "reverse".
alias reverse {

  ;Set local variable %x to 1 and unset %r.
  var %x = 1,%r

  ;Loop, which continues as long as $mid returns something.
  ;$1 being the input, %x being the position and 1 being the amount of characters $mid is allowed to return at once.
  ;It literally goes character by character the given input until it reaches the end, which is $null.
  while ($mid($1,%x,1) != $null) {

    ;Set local variable %r to whatever $mid returned in the loop above ($v1), and attach it to the left side of whatever is in %r, if there is anything.
    var %r = $+($v1,%r)

    ;Increase %x by 1.
    inc %x
  }

  ;Return the result.
  return %r
}

Last edited by Dazuz; 16/12/15 04:57 PM. Reason: Boredom strikes!
Re: text backwards [Re: Dazuz] #256076 16/12/15 05:29 PM
Joined: May 2014
Posts: 35
P
Perl Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: May 2014
Posts: 35
Thanks, I was interested to learn, I appreciate it very much, it is very important for me to understand what they do codes. a greeting


pd: with your explanation, I understand better now if you like it does :)) thank !!

Last edited by Perl; 16/12/15 05:31 PM.