Friday 30 August 2013

Reversing a String: How to reverse a string without using a reverse function

Hi Folks,
I am certain the most of you have come accross the situation like this, This is one of the most common interview question of any programing interview(No matter whether it is Scripting Lang or Prog Lang, you are gonna get this question).

No  in my question I have below example

sampleString="softwareTestingPerfection"
 
Notice that the data is used in String and not in Array and this is where it gets intresting
Now I want the output as

outputString="noitcefrePgnitseTerawtfos"

Now in conventional way we would have the stirng stored in variable array but that is the main feature in this example.We will index the each element of the string without using the actual array.

sampleString="softwareTestingPerfection"

strlen= len(samplestring)
outputString=""
For i=1 to strlen
   outputString=mid(sampleString,i,1)&outputString
Next
msgbox outputString


Hope this will help!!!!!!

for any query/comment please write on the section below


No comments:

Post a Comment