Various ways to Reverse String in UFT/QTP using Vbscripting – User friendly Tech help
Scenario:- We need to Reverse a String, without using Vb-scripting Inbuilt Function(strReverse)n
Solution1:- We will use “Mid” function for reversing the Input String
n
Example Code:-
n
sRev = "UFTHELP, Ur First Testing Help"
Msgbox fnReverse(sRev)
Public Function fnReverse(sRev)
for i = 1 to len(sRev)
sNew = mid(sRev,i,1) &sNew
next
fnReverse = sNew
End Function
n
nn
n
Solution 2:- We’ll be using Split function and then combine the string in Reverse order.This technique is recommended incase we wont our words order to reversed rather than each character
n
Example Code:-
n
sRev = "UFTHELP, Ur First Testing Help"
Msgbox fnReverse(sRev)
Public Function fnReverse(sRev)
'Using Split function
arr = split(sRev, " ")
for i = Ubound(arr) to 0 Step -1
sNew = sNew & " " &arr(i)
next
fnReverse = sNew
End Function
n
n