Reverse a string without using strReverse or Mid Function

5
127
Welcome to automated-360.com

Recently one of my colleagues put an interesting situation to script in vbs. It was to reverse a string without using Mid or string Reverse function. For example, if the given string is – AUTOMATED 360 , the result should be DETAMOTUA 063.

Since most of us are likely to use the built in functions and not to think about other ways of doing the same, it sounds like a bit tough. I also had the same situation, but a few minutes of analysis resulted me the solution for the same. The trick is to put all the characters in array and then print the array in reverse order.

below is the code using array to reverse the string.

Here is one more nice way to do this using array again.

5 COMMENTS

  1. Hello Saket,

    Nice code for reverse string, I have faced this question in most of interviews.

    Can I have function for generating the qtp results with screen shots in a PDF or word formate please?

    Thanks in advance.

    REgards,

    Sreekanth

  2. Sub abc()

    srt = “Automation is good”
    Count = Split(srt, ” “)
    ‘MsgBox UBound(Count)
    For a = 0 To UBound(Count)
    For i = 1 To Len(Count(a))
    temp1 = temp1 & Left(Right(Count(a), i), 1)

    Next

    temp2 = temp2 & ” ” & temp1

    temp1 = “”
    Next

    MsgBox temp2
    End Sub

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.