---
title: "How to reverse the order of words in a given string?"  
description: "How to reverse the order of words in a given string?"  
author: "Ashutosh Patel"  
published: 2023-02-08  
updated: 2023-02-08  
canonical: https://www.mindstick.com/forum/157387/how-to-reverse-the-order-of-words-in-a-given-string  
category: "c#"  
tags: ["c#", "java"]  
reading_time: 1 minute  

---

# How to reverse the order of words in a given string?

How to change the [order](https://www.mindstick.com/articles/12276/how-timely-order-deliveries-can-improve-customer-experience) of whole words given in a [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp)?

## Replies

### Reply by Revati S Misra

This is the simple C# program to reverse the order of words in a given string,

```cs
using System;
using System.Text;
namespace HelloWorld
{
  class Program
  {
    static void Main(string[] args)
    {
    Program.ReverseWordOrder("Hello World"); 
    }
    static void ReverseWordOrder(string str)
    {
        int i;
        StringBuilder reverseWord = new StringBuilder();

        int Start = str.Length - 1;
        int End = str.Length - 1;

        while (Start > 0)
        {
            if (str[Start] == ' ')
            {
                i = Start + 1;
                while (i <= End)
                {
                    reverseWord.Append(str[i]);
                    i++;
                }
                reverseWord.Append(' ');
                End = Start - 1;
            }
            Start--;
        }

        for (i = 0; i <= End; i++)
        {
            reverseWord.Append(str[i]);
        }
       Console.WriteLine(reverseWord.ToString());
    }
  }
}
Output:  World Hello
```


---

Original Source: https://www.mindstick.com/forum/157387/how-to-reverse-the-order-of-words-in-a-given-string

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
