Code
//利用hashtable删除一个文本与另一个文本想重复内容
private void button1_Click(object sender, EventArgs e)
{
//少数号码
string phone = "";
string path = "C:\\Documents and Settings\\Administrator\\桌面\\615.txt";
FileStream fs = new FileStream(path, FileMode.Open);
Hashtable ht = new Hashtable();
using (StreamReader sr = new StreamReader(fs))
{
string line = sr.ReadLine();
while (line != null)
{
if (!ht.ContainsKey(line))
{
ht.Add(line,1);
}
line = sr.ReadLine();
}
}
//多数号码
string phone2="";
string path2 = "C:\\Documents and Settings\\Administrator\\桌面\\123.txt";
FileStream fs2 = new FileStream(path2, FileMode.Open);
string content = "";
using (StreamReader sr = new StreamReader(fs2))
{
content = sr.ReadToEnd();
ICollection ic = ht.Keys;
foreach (string s in ic)
{
content = content.Replace(s+"\r\n", "");
}
}
//写入另一个文本
string path3 = "C:\\Documents and Settings\\Administrator\\桌面\\111.txt";
FileStream fs3 = new FileStream(path3, FileMode.OpenOrCreate);
using (StreamWriter sw = new StreamWriter(fs3))
{
sw.WriteLine(content);
}
}
//利用hashtable删除一个文本与另一个文本想重复内容
private void button1_Click(object sender, EventArgs e)
{
//少数号码
string phone = "";
string path = "C:\\Documents and Settings\\Administrator\\桌面\\615.txt";
FileStream fs = new FileStream(path, FileMode.Open);
Hashtable ht = new Hashtable();
using (StreamReader sr = new StreamReader(fs))
{
string line = sr.ReadLine();
while (line != null)
{
if (!ht.ContainsKey(line))
{
ht.Add(line,1);
}
line = sr.ReadLine();
}
}
//多数号码
string phone2="";
string path2 = "C:\\Documents and Settings\\Administrator\\桌面\\123.txt";
FileStream fs2 = new FileStream(path2, FileMode.Open);
string content = "";
using (StreamReader sr = new StreamReader(fs2))
{
content = sr.ReadToEnd();
ICollection ic = ht.Keys;
foreach (string s in ic)
{
content = content.Replace(s+"\r\n", "");
}
}
//写入另一个文本
string path3 = "C:\\Documents and Settings\\Administrator\\桌面\\111.txt";
FileStream fs3 = new FileStream(path3, FileMode.OpenOrCreate);
using (StreamWriter sw = new StreamWriter(fs3))
{
sw.WriteLine(content);
}
}