Please help me with the task: "Remove double spaces"

Hello, I’m working on this task:

Write a program that removes all double spaces in a given string. It should read a string from the console and store it in the variable input. You should declare input by using var. Pay attention only to double spaces; we are not focusing on triple or more spaces in this task. For example:
>Are you ready to save the world?
Are you ready to save the world?

Here is my code:


namespace LearningVar
{
   class DoubleSpaces
   {
       static void Main(string[] args)
       {
        var input = Console.ReadLine();
        for(var i = 0;i<input.Length;i++){
            if(input[i] != ' '){
               Console.Write(input[i]);  
            }
           }
        } 
  
       }
   }


Can anyone please help me to solve it?
I use for loop to iterate through the string characters when input[i] is not equal space.
how to add one space to each word?

Ok, so what you are doing will remove all spaces in the string, right? To remove only double spaces, you need to check if 2 symbols in the row are spaces, for example, input[i] and input[i+1].
Only in the case where both are spaces - you should NOT perform the Console.Write

Hope this makes sense!

P.S. Make sure to not get out of bounds when you add or subtract 1 from i.