The VBScript Network and Systems Administrator's Cafe

Nov 26 2008   2:43PM GMT

Reversing a string with VBScript using the mid function

Jerry Lees Jerry Lees Profile: 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

WScript.Echo NewStr

2  Comments on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.
  • parth123
    Can you explain the code to me in details
    20 pointsBadges:
  • parth123
    Newstr=NewStr&char how does it work
    20 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: