Function to reverse the order of words

C#

public static string Reverse(string sentence)
{
        string[] words = sentence.Split(' ');

        Array.Reverse(words);

        return string.Join(" ", words);
}

VB.NET

Public Shared Function Reverse(sentence As String) As String

          Dim words As String() = sentence.Split(" "C)

          Array.Reverse(words)

          Return String.Join(" ", words)

End Function

Input:  Hello! World

Output:  World Hello!

1 comment :

  1. This comment has been removed by a blog administrator.

    ReplyDelete