Scenario:- We need to Reverse a String, without using Vb-scripting Inbuilt Function(strReverse)

Solution1:- We will use “Mid” function for reversing the Input String

Example Code:-


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

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

Example Code:-  


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

Leave a Reply

Your email address will not be published. Required fields are marked *