下一站天后
今朝的容颜老于昨晚
博客园
::
首页
::
新随笔
::
联系
::
订阅
::
管理
::
88 随笔 :: 0 文章 :: 54 评论 :: 0 引用
2009年6月23日
#
利用hashtable删除文本重复内容
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);
}
}
posted @ 2009-06-23 17:08 孙雅玲 阅读(136) 评论(0)
编辑
<
2009年6月
>
日
一
二
三
四
五
六
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
公告
昵称:
孙雅玲
园龄:
3年7个月
粉丝:
5
关注:
2
搜索
常用链接
我的随笔
我的评论
我的参与
最新评论
我的标签
随笔分类
网站架构与性能优化(1)
(rss)
Ajax(2)
(rss)
c#(28)
(rss)
html(6)
(rss)
js(14)
(rss)
sql server(12)
(rss)
工具与控件(7)
(rss)
配置环境(8)
(rss)
语法(12)
(rss)
随笔档案
2011年8月 (1)
2011年7月 (1)
2010年7月 (1)
2009年10月 (1)
2009年9月 (2)
2009年6月 (5)
2009年5月 (1)
2009年4月 (6)
2009年3月 (4)
2009年2月 (9)
2009年1月 (3)
2008年12月 (5)
2008年11月 (8)
2008年10月 (8)
2008年9月 (21)
2008年8月 (12)
积分与排名
积分 - 31255
排名 - 3433
最新评论
阅读排行榜
评论排行榜
推荐排行榜