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?