Reversing a string with VBScript using the mid function
Posted by: Jerry Lees
As a part of the VBScript encryption I mentioned working on I needed to find a way to reverse a string. Doing this yielded many possibilities, but this piece of code seemed to work the best (and was the simplest) out of all the pieces of code I came up with to reverse a string.
It’s simple, but effective and you could easily wrap a function statement around it to create your own function to reverse a string. Here is the code:
Option Explicit
Dim MyStr, char, NewStr, x, y
MyStr = “Reverse Me!”
y = Len(MyStr)
For x = y To 1 Step -1
char = Mid(MyStr,x,1)
NewStr = NewStr & char
Next
WScript.Echo NewStr



You must be logged-in to post a comment. Log-in/Register