Here is my new solution for you using Heap's algorithm to determine all possible permutations of your input string. Please leave me a comment and let me know how it worked for you. Marking this as an answer would be nice too. :)
EDIT: changed from C# to VB (I forgot) :)
Private Sub Form1_Load(sender As Object, e As EventArgs)
Dim word As String = "I like cake"
Dim split As String() = word.Split(New Char() {" "c},
StringSplitOptions.RemoveEmptyEntries)
Dim words As New List(Of String)()
HeapPermute(words, split, split.Length)
End Sub
Private Sub HeapPermute(words As List(Of String), split As String(), splitCount As Integer)
Dim n As Integer = splitCount
If n = 1 Then
Dim temp As String = ""
For i As Integer = 0 To split.Length - 1
temp += split(i) & " "
Next
words.Add(temp.TrimEnd(" "c))
Else
For i As Integer = 0 To n - 1
HeapPermute(words, split, (n - 1))
If n Mod 2 = 1 Then
Dim temp As String = split(0)
split(0) = split(n - 1)
split(n - 1) = temp
Else
Dim temp As String = split(i)
split(i) = split(n - 1)
split(n - 1) = temp
End If
Next
End If
End Sub
And here is the output from my test on this particular string.
I like cake
like I cake
cake I like
I cake like
like cake I
cake like I
//////////////////////////////////////////////////////////
Original Solution
/////////////////////////////////////////////////////////
Try this
Dim original As String = "I like cake"
Dim words As String() = original.Split(New Char() {" "},
StringSplitOptions.RemoveEmptyEntries)
Array.Reverse(words)
Dim reversed As String = String.Join(" ", words)
reversed will be "cake like I"
//////////////////////////////////////////////////////////
END Original Solution
/////////////////////////////////////////////////////////