In the following code:
static void Main(string[] args)
{
string MultiLineString = @"This is a
random sentence";
int index=0;
string test = "";
Console.WriteLine(MultiLineString[9].ToString()); //it should print 'r' but it prints a white space
for (int i = 0; i < MultiLineString.Length; i++)
{
if (MultiLineString[i] == 'r')
index = i;
}
Console.WriteLine(index); // 11 is the index of 'r' in "random"
foreach (char ch in MultiLineString)
if (ch == ' ')
test += "_";
else
test += ch;
Console.WriteLine(test);
// the output is:
// This_is_a
//random_sentece
}
I'm having hard time trying to realyze what is happening in the 9-10 indexs. At first I thought it was a space the was somehow created when I skiped a line but then it was not included in the test string.
Thanks in advance.