Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing string in reverse order

Status
Not open for further replies.

ReportDr00

IS-IT--Management
Mar 2, 2007
194
US
Hi
I have below incoming string and needs to be parsed and placed it in reverse order
Incoming String
labname1^labresults1^labname2^labresults2^labname3^labresults3

Output String
labname3^labresults3^labname2^labresults2^labname1^labresults1

Appreciate feedback

Regards
 
Your post was a bit misleading so I am glad you gave an illustration as this is not *technically* reverse order. If this was reverse order it would have been:

labresults3^labname3^labresults2^labname2^labresults1^labname1

Anyway, here you go.

Code:
Dim InputStr
Dim OutputStr
Dim aryTemp
Dim aryFinal

InputStr = "labname1^labresults1^labname2^labresults2^labname3^labresults3"
aryTemp = Split(InputStr, "^")
ReDim aryFinal(UBound(aryTemp))
For i = UBound(aryTemp) To LBound(aryTemp) Step -2
    OutputStr = OutputStr & aryTemp(i - 1) & "^" & aryTemp(i) & "^"
Next
MsgBox Left(OutputStr, Len(OutputStr) - 1)

Swi
 
Sorry, you can get rid of the following two lines of code:

Dim aryFinal
ReDim aryFinal(UBound(aryTemp))

They are unused.

Swi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top