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
Next

WScript.Echo NewStr

1  Comment 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.
  • RakeshY
    str=inputbox("Enter the string: ")
    str1=len(str)
    a=Left(str,1)
    for i=1 to str1
       str2=Left(str,i)
    if len(str2)>1 then
      str3=Right(str2,1)&temp
      temp=str3
    end if
    next
    msgbox temp&a

    10 pointsBadges:
    report

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: