Print Substrings of a String in Reverse Order


strText = 
"QTP Sreenu Blog"

Output should be "Blog Sreenu QTP"

Using Split Funtion

arrSubStrings = Split(strText)
For i=UBound(arrSubStrings) To0Step -1
    strRev = Trim(strRev) & " " & arrSubStrings(i)
Next
MsgBox strRev

Without using any built-in functions

strText = "QTP Sreenu Blog"
Set oRegExp = NewRegExp
oRegExp.Pattern = "\d|\D|\s|\S|\t|\w|\W"'This pattern matches with any character
oRegExp.Global = True
Set oItems = oRegExp.Execute(strText)
iArrayIndex = 0
For i=0To oItems.Count-1
    If oItems(i) <> " "Then
        strSub = strSub & oItems(i)
    Else
        ReDimPreserve arrSubs(iArrayIndex)
        arrSubs(iArrayIndex) = strSub
        strSub = ""
        iArrayIndex = iArrayIndex + 1
    EndIf
Next
ReDimPreserve arrSubs(iArrayIndex)
arrSubs(iArrayIndex) = strSub
For i=UBound(arrSubs) To0Step -1
    strRev = strRev & " " & arrSubs(i)
Next
MsgBox strRev

No comments:

Post a Comment