Alexander Sukhanov Alexander Sukhanov - 1 year ago 199
C# Question

DownloadString skips newline characters

I want to import text data from Google Finance, and I use this http address as a parameter to

. However, the resulting string misses any newline characters, so it is really difficult to parse. Any ideas?

Answer Source

The line ends returned from the stream are \n opposed to the default Windows line ends \r\n (which is represented in Environment.NewLine on Windows).

Try to split on all of the possible combinations of \r and \n:

WebClient wc = new WebClient();
string s = wc.DownloadString(",o,h,l,c,v&df=cpct&q=AAPL");

string[] lines = s.Split(new string[] { Environment.NewLine, "\n", "\"r" }, StringSplitOptions.None);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download