问题描述
我想从 Google 财经导入文本数据,我使用这个 http 地址作为 DownloadString
http://www.google.com/finance/getprices?i= 的参数1200&p=1d&f=d,o,h,l,c,v&df=cpct&q=AAPL
.但是,生成的字符串缺少任何换行符,因此解析起来非常困难.有任何想法吗?
I want to import text data from Google Finance, and I use this http address as a parameter to DownloadString
http://www.google.com/finance/getprices?i=1200&p=1d&f=d,o,h,l,c,v&df=cpct&q=AAPL
. However, the resulting string misses any newline characters, so it is really difficult to parse. Any ideas?
推荐答案
从流返回的行尾是 \n
与默认的 Windows 行尾 \r\n
(在 Windows 上的 Environment.NewLine
中表示).
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).
尝试拆分 \r
和 \n
的所有可能组合:
Try to split on all of the possible combinations of \r
and \n
:
WebClient wc = new WebClient();
string s = wc.DownloadString("http://www.google.com/finance/getprices?i=1200&p=1d&f=d,o,h,l,c,v&df=cpct&q=AAPL");
string[] lines = s.Split(new string[] { Environment.NewLine, "\n", "\"r" }, StringSplitOptions.None);
这篇关于DownloadString 跳过换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!