I'm trying to use a stack object to reverse the order of words (not letters) in a sentence. I'm fairly sure that the split and push methods are working, but I can only get the first word (i.e. the first word in the original sentence), to be displayed.
I have the following code:
Private Sub btnReverse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReverse.Click Dim s As New Stack Dim sentence, word, reverse As String Dim words As Array sentence = txtOriginalOrder.Text words = sentence.Split(" ") For Each word In words s.Push(word) Next Do txtReverseOrder.Text = s.Pop & " " Loop Until s.Count = 0 End Sub
I think the Do loop is the problem, but nothing I've tried makes any different output.
Anyone know how I can fix this?