0

I have a file which looks like this:

1

2

3

4
5
6
7

I want to read it in and remove the newline characters. My attempt is this:

StreamReader reader = new StreamReader("t.txt");
string text = reader.ReadToEnd();
text.Replace(System.Environment.NewLine, " ");
Console.WriteLine(text);

But the output is still the same as above. I want the output to be:

1 2 3 4 5 6 7

What am I doing wrong?

Peter B
  • 22,460
  • 5
  • 32
  • 69
user394334
  • 243
  • 1
  • 10

1 Answers1

5

Strings are immutable, the string being returned by replace should be formatted like you expect.

ScottyD0nt
  • 348
  • 2
  • 8