C# 在2个文件中合并百万行URL
文件A B包含一百万个URLC# 在2个文件中合并百万行URL,c#,C#,文件A B包含一百万个URL 1、逐一浏览文件A中的url 2、提取subdomain.com() 3、如果subdomain.com存在文件B,则将其保存到文件C。 用C#获取文件C的最快方法是什么? 谢谢。 当我使用readline时,它没有什么不同 // stat DateTime start = DateTime.Now; int totalcount = 0; int n1; if (!i
1、逐一浏览文件A中的url
2、提取subdomain.com()
3、如果subdomain.com存在文件B,则将其保存到文件C。
用C#获取文件C的最快方法是什么?
谢谢。
当我使用readline时,它没有什么不同
// stat
DateTime start = DateTime.Now;
int totalcount = 0;
int n1;
if (!int.TryParse(num1.Text, out n1))
n1 = 0;
// memory
dZLinklist = new Dictionary<string, string>();
// read file
string fileName = openFileDialog1.FileName; // get file name
textBox1.Text = fileName;
StreamReader sr = new StreamReader(textBox1.Text);
string fullfile = File.ReadAllText(@textBox1.Text);
string[] sArray = fullfile.Split( '\n');
//IEnumerable<string> sArray = tool.GetSplit(fullfile, '\n');
//string sLine = "";
//while (sLine != null)
foreach ( string sLine in sArray)
{
totalcount++;
//sLine = sr.ReadLine();
if (sLine != null)
{
//string reg = "http[s]*://.*?/";
//Regex R = new Regex(reg, RegexOptions.Compiled);
//Match m = R.Match(sLine);
//if(m.Success)
int length = sLine.IndexOf(' ', n1); // default http://
if(length > 0)
{
//string urls = sLine.Substring(0, length);
dZLinklist[sLine.Substring(0,length)] = sLine;
}
}
}
TimeSpan time = DateTime.Now - start;
int count = dZLinklist.Count;
double sec = Math.Round(time.TotalSeconds,2);
label1.Text = "(" + totalcount + ")" + count.ToString() + " / " + sec + " = " + (Math.Round(count / sec,2)).ToString();
sr.Close();
//stat
DateTime start=DateTime.Now;
int totalcount=0;
int-n1;
如果(!int.TryParse(num1.Text,out n1))
n1=0;
//记忆
dZLinklist=新字典();
//读取文件
字符串文件名=openFileDialog1.fileName;//获取文件名
textBox1.Text=文件名;
StreamReader sr=新的StreamReader(textBox1.Text);
string fullfile=File.ReadAllText(@textBox1.Text);
字符串[]sArray=fullfile.Split('\n');
//IEnumerable sArray=tool.GetSplit(fullfile,“\n”);
//字符串sLine=“”;
//while(sLine!=null)
foreach(sArray中的字符串sLine)
{
totalcount++;
//sLine=sr.ReadLine();
if(sLine!=null)
{
//string reg=“http[s]*://.*?/”;
//Regex R=新的Regex(reg,RegexOptions.Compiled);
//匹配m=R.Match(sLine);
//如果(m.成功)
int length=sLine.IndexOf(“”,n1);//默认http://
如果(长度>0)
{
//字符串URL=sLine.Substring(0,长度);
dZLinklist[sLine.Substring(0,长度)]=sLine;
}
}
}
TimeSpan time=DateTime.Now-start;
int count=dZLinklist.count;
双秒=数学轮(时间总秒,2);
label1.Text=“(“+totalcount+”)”+count.ToString()+“/”+sec+“=”+(数学圆整(计数/秒,2)).ToString();
高级关闭();
我倾向于使用Microsoft LogParser处理大文件:。您是否仅限于以所描述的方式实现它?在大多数机器上,一百万个URL应该可以放在内存中。将文件B中的子域存储在字典中。通过文件A循环查找字典中的子域,如果存在,将其写入文件C。谢谢,现在我发现瓶颈是indexOf,我使用它来获取域。我想这是获得域名的更快的方法。那么有更好的方法吗?没有,任何获取文件C的方法都可以。但我想LogParser在这方面会很慢。因为这对于这个简单的工作来说并不特别。而且它不容易使用,或者如何使用LogParser来获取文件C?