|
flashstar_2000 Beginner
Joined: 24 Nov 2003 Posts: 11
|
Posted: 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 |
|
|
|
Toetag Magician
Joined: 10 Oct 2000 Posts: 356 Location: USA
|
Posted: 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 |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: 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)}}
} |
|
|
|
Toetag Magician
Joined: 10 Oct 2000 Posts: 356 Location: USA
|
Posted: Fri Dec 05, 2003 5:47 pm |
i knew Lightbulb would have a better idea :)
|
|
|
|
|
|