So basically I have an input string and I have to return a string after adding space after every character in the string.
Eg. input = abcd output=a b c d
I wrote this piece of code:
class Program
{
static void Main()
{
string input1 = "abcd";
char[] output = new char[999];
int j = 0;
for (int i = 0; i < input1.Length; i++)
{
output[j] = input1[i];
j = j + 1;
output[j] =' ';
}
Console.Write(output[1]); //Why does this print b? I have inserted a blank space at index 1, right?
for (int i = 0; i < output.Length; i++)
Console.Write(output[i]);
string op = new string(output);
return op;
}
}
So that's my question, how does it get b at index 1 when I have inserted a blank space.
I am not sure if there are any other shortcuts to do this task. I am completely new to C#. Thanks for all the help. :)
EDIT: This is my first time posting here, sorry for the messed up formatting of the text and code.