您的位置:首页 > 其它

利用hashtable删除文本重复内容

2009-06-23 17:08 239 查看
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);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐