Hello, I'm trying to remove last spaces from some strings however my function behaves strangely.

For example when my string is: "word1 word2 word3 word4 "

... and function is
Code:
Private Function TrimLastSpaces(s As String) As String

        Dim i As Integer
        For i = s.Length To 0 Step -1

            If (Mid(s, i - 2, i - 1) = " ") Then
                Console.WriteLine("s = " & s)
                s = Mid(s, 1, s.Length - 2)
                i = s.Length()
            Else
                Console.WriteLine(Mid(s, i - 2, i - 1))
                Exit For
            End If
        Next

        Return s

    End Function
it doesn't go in "if" statement, it goes in "else" statement and outputs three space charcters while I'm expecting it to remove space characters one by one.

Maybe it's a very simple thing I'm missing but I couldn't figure it out.