Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
flashstar_2000
Beginner


Joined: 24 Nov 2003
Posts: 11

PostPosted: Fri Dec 05, 2003 2:45 am   

Reverseing strings
 
Heres a question, how do i reverse a string?
like if "drib" is stored to @var, how can i turn it around to "bird"? this is ment for a trigger sooo... lol
Reply with quote
Toetag
Magician


Joined: 10 Oct 2000
Posts: 356
Location: USA

PostPosted: Fri Dec 05, 2003 4:57 am   
 
Here's one way. I'm sure there are probably better ways, but here's the rough idea. I'm sure LightBulb or one of the other smarter than me's can clean this up, or even offer something easier.

Note: tested off line using: #Show Birdie is <pattern>.

Trigger Pattern:
Birdie is (%w).

Command:
#var LengthCount _nodef _nodef _nodef
#var LoopIndex _nodef _nodef _nodef
#var TempString _nodef _nodef _nodef
LoopIndex = 0
TempString = ""
LengthCount = %len(%1)
#WHILE (@LoopIndex <= @LengthCount) {
TempString = @TempString%copy( %1, @LengthCount - (@LoopIndex - 1), 1)
#math LoopIndex {@LoopIndex + 1}
}
#show @TempString


Birdie is flying.
gniylf
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Fri Dec 05, 2003 4:51 pm   
 
Same general approach. Loop through the string from back to front.
#VAR backwards {drib}
#AL flashstar {
#VAR forwards %null
#LOOP %len( @backwards),1 {#VAR forwards {@forwards%copy( @backwards, %i, 1)}}
}
Reply with quote
Toetag
Magician


Joined: 10 Oct 2000
Posts: 356
Location: USA

PostPosted: Fri Dec 05, 2003 5:47 pm   
 
i knew Lightbulb would have a better idea :)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net