R
R
Rifat2016-02-17 23:24:45
.NET
Rifat, 2016-02-17 23:24:45

What could be the reason for this behavior of strings in C#?

Faced with an incomprehensible situation.
The code:

WebClient client = new WebClient();
string html = client.DownloadString("http://www.imdb.com/title/tt0452046/");
File.WriteAllText("index.html", html);

I put a breakpoint on line 3 and look at the value of the html variable in the Text Visualizer. I select all the text, put it on the clipboard, create a text file called example.html and paste the data from the clipboard into it, save it.
Further on line 3, the value of the same variable is written to the index.html file.
The problem is that the contents of these two files end up being completely different.
The first file is ~33 KB, the second is ~232 KB
What is it? Why is the value of the html variable at runtime the same value, but a completely different value is written to the file?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Martyanov, 2016-02-17
@vilgeforce

You put a text representation in some kind of encoding into the buffer, and write raw data to the file as it is. Least. There are only bytes and nothing but bytes that goes into your buffer - only the Studio knows.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question