This is a help and support site for everyone for tips, tricks and tutorials on QTP / UFT, automation frameworks & concepts. If you are planning to do HP Certification, this is the place to learn...
VBScript Program to reverse a string without using strreverse
'Program to reverse a string without using strreverse
MyStr = inputbox("Enter the String:")
nCnt = Len(MyStr)
For i = 1 to nCnt
RevStr = Mid(MyStr,i,1)&RevStr
Next
Msgbox RevStr
@ Chandrasekar : We need to repeat the reversing for every character. Where as in your logic, you are excluding one of the characters if you are trying from 1st character till last-1 (you are missing the last character). Looks like your logic needs a correction. BTW I already executed the above code and it works fine. Please let me know if you need any more information.
Thanks aLot
ReplyDelete
DeleteDim str, revstr, strlen
Str = "TestingQ"
strlen = Len(Str)
For i = strlen To 1 Step -1
revstr = revstr + mid (Str,i,1)
Next
print revstr
'Msgbox revstr
If instr(revstr, "QgnitseT") Then
Reporter.ReportEvent micPass, "verify rev str", "reverse string pass"
print "reverrse done is" & true
Else
Reporter.ReportEvent micFail, "verify rev str", "reverse string fail"
print "reverse done is " & false
End If
What is use of
Deleteprint "reverse done is " & false or
print "reverse done is " & true ?
banda
ReplyDeletethanks a lot
ReplyDeleteThis is wrong.
ReplyDeletereverse the loop
For nCnt to 1 Step -1
@ Chandrasekar : We need to repeat the reversing for every character. Where as in your logic, you are excluding one of the characters if you are trying from 1st character till last-1 (you are missing the last character). Looks like your logic needs a correction. BTW I already executed the above code and it works fine. Please let me know if you need any more information.
Deletecan u please elaborate the logic
Deletehello wrong answer
ReplyDeleteI dont understand.. could you please elaborate?
DeleteTry this:
ReplyDeletedim a,b
str = inputbox("enter the string:")
For n = len(str) to 1 step- 1
b=Mid(str,n,1)
a = a+b
Next
Msgbox ("the string is"&a)
I too did the same at home, the ans is as follows:
DeleteDim str, revstr, strlen
Str = "TestingQ"
strlen = Len(Str)
For i = strlen To 1 Step -1
revstr = revstr + mid (Str,i,1)
Next
print revstr
'Msgbox revstr
If instr(revstr, "QgnitseT") Then
Reporter.ReportEvent micPass, "verify rev str", "reverse string pass"
print "reverrse done is" & true
Else
Reporter.ReportEvent micFail, "verify rev str", "reverse string fail"
print "reverse done is " & false
End If
hi,
ReplyDeleteCan any one correct my code if it need to as am not getting required result
am trying to reverse a string
Dim x
x=inputbox("Enter a string")
cnt=len(x)
Do until cnt=0
y = mid(x,cnt,1)&y
cnt=cnt-1
Loop
msgbox y
Hi jayasree,
Deleteplease tell me..........
what is "cnt"
cnt is a variable
Deletewhich is assigned Zero
@ jayasree - this will work :
ReplyDeleteDim x
x=inputbox("Enter a string")
cnt=len(x)
Do until cnt=0
y = y&mid(x,cnt,1)
cnt=cnt-1
Loop
msgbox y
Any know, How to open a windows based file. But should not using systemutil.run and invokeapplication. Any alternative way is their.
ReplyDeleteoption explicit
ReplyDeletedim i,str1,str,slen
str = "string"
i = 1
slen = len(str)
for i = slen to 1 step -1
str1 = str1&mid(str,i,1)
next
msgbox str1
Thaks Acharya
ReplyDeleteI appreciate Nrusingha Acharya
ReplyDeleteyou put it in a simple way.
Ya u r correct..
DeletePlease find my approach below.
ReplyDeleteDim myStr, revStr, nCnt, nVar
myStr = "Test"
nCnt = Len(myStr)
For i=nCnt To 1 Step-1
nVar = Mid(myStr, i, 1)
revStr = revStr & nVar
Next
print revStr