在一個文本文件中比較每倏記錄輸出相同的行 在一個文本文件中比較每倏記錄輸出相同的行比如說:文件:11231234564567891234567890123123那麼輸出結果:123123456請各位幫賜教!謝謝! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string fileName = System.IO.Path.Combine(Application.StartupPath,"1.txt"); string tmp = null; Hashtable ht = new Hashtable(); using (System.IO.StreamReader sr = new System.IO.StreamReader(fileName)) { while ((tmp = sr.ReadLine()) != null) if (tmp.Trim().Length != 0) if (ht.Contains(tmp)) sw.WriteLine(tmp); else ht[tmp] = 0; } ht[tmp] = 0; 请问这个是什么意思啊! sw.WriteLine(tmp); 改成Consoleht[tmp] = 0; 主要是用hashtable的键,随便赋了个0 Console.WriteLine(tmp); 是控制台输出winform程序,可以用MessageBox.Show弹出来看看,或者写到一个文本里面,看结果的方法多的很,看你自己需要 string fileName = System.IO.Path.Combine(Application.StartupPath,"1.txt"); string str= null; using (System.IO.StreamReader sr = new System.IO.StreamReader(fileName)) { while ((tmp = sr.ReadLine()) != null) { if (!tempList.Contains(str)) { tempList.Add(str); //将不重复的权限数据录入到tempList }else{输出 str}}} ArrayList tempList = new ArrayList(); string fileName = System.IO.Path.Combine(Application.StartupPath,"1.txt"); string str= null; string strNew="";using (System.IO.StreamReader sr = new System.IO.StreamReader(fileName)) { while ((tmp = sr.ReadLine()) != null) { if (!tempList.Contains(str)) { tempList.Add(str); //将不重复的权限数据录入到tempList } else { strNew =strNew+str; } } FileStream fs = new FileStream("d:/2.txt", FileMode.OpenOrCreate, FileAccess.Write); StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("GB2312"));//通过指定字符编码方式可以实现对汉字的支持,否则在用记事本打开查看会出现乱码 sw.Flush(); sw.BaseStream.Seek(0, SeekOrigin.Begin); sw.Write(Environment.NewLine); sw.WriteLine(strNew); sw.Flush(); sw.Close(); 还是不行咯,相同的数据还是输不出来,是空白的! if (!tempList.Contains(str)) { tempList.Add(str); //将不重复的权限数据录入到tempList } else { strNew =strNew+str; } else 好像都没落执行过呢!所以输了,出来的都是空值! string fileName = System.IO.Path.Combine(Application.StartupPath,"1.txt"); string tmp = null; Hashtable ht = new Hashtable(); using (System.IO.StreamReader sr = new System.IO.StreamReader(fileName)) { fileName = System.IO.Path.Combine(Application.StartupPath,"2.txt"); System.IO.StreamWriter sw = new System.IO.StreamWriter(fileName); while ((tmp = sr.ReadLine()) != null) { if (tmp.Trim().Length != 0) if (ht.Contains(tmp)) sw.WriteLine(tmp); else ht[tmp] = 0; } sw.Close(); } 代码好用啊static void Main(string[] args) { string fileName ="c:/1.txt"; string tmp = null; Hashtable ht = new Hashtable(); using (System.IO.StreamReader sr = new System.IO.StreamReader(fileName)) { while ((tmp = sr.ReadLine()) != null) { if (tmp.Trim().Length != 0) if (ht.Contains(tmp)) { //System.IO.StringWriter sw = new System.IO.StringWriter(); //sw.WriteLine(tmp); System.Console.WriteLine(tmp); } else { ht[tmp] = 0; } } System.Console.ReadLine(); } } C#与C++的类型问题 200分继续求[C#屏幕取词] SQL语句 如何获得update所影响的行 页面图片抓取小程序.net winform 菜鸟提问:如何替换回车和换行 Activator.CreateInstance的一个问题 高分,C#的socket不能正常收发中文,英文及数字都正常,急救我一下 用C#如何判断本机是否联入互联网 怎样调用Power Point提供的组件来操作ppt文件。 xml文件读写问题 增加一个数据库访问 求助:一个小游戏的实现
string tmp = null;
Hashtable ht = new Hashtable();
using (System.IO.StreamReader sr = new System.IO.StreamReader(fileName))
{
while ((tmp = sr.ReadLine()) != null)
if (tmp.Trim().Length != 0)
if (ht.Contains(tmp))
sw.WriteLine(tmp);
else
ht[tmp] = 0;
}
改成Consoleht[tmp] = 0; 主要是用hashtable的键,随便赋了个0
是控制台输出winform程序,可以用MessageBox.Show弹出来看看,
或者写到一个文本里面,看结果的方法多的很,看你自己需要
string str= null;
using (System.IO.StreamReader sr = new System.IO.StreamReader(fileName))
{
while ((tmp = sr.ReadLine()) != null)
{
if (!tempList.Contains(str))
{
tempList.Add(str); //将不重复的权限数据录入到tempList
}
else
{
输出 str
}
}
}
string str= null;
string strNew="";using (System.IO.StreamReader sr = new System.IO.StreamReader(fileName))
{
while ((tmp = sr.ReadLine()) != null)
{
if (!tempList.Contains(str))
{
tempList.Add(str); //将不重复的权限数据录入到tempList
}
else
{
strNew =strNew+str;
}
}
FileStream fs = new FileStream("d:/2.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("GB2312"));//通过指定字符编码方式可以实现对汉字的支持,否则在用记事本打开查看会出现乱码
sw.Flush();
sw.BaseStream.Seek(0, SeekOrigin.Begin);
sw.Write(Environment.NewLine);
sw.WriteLine(strNew);
sw.Flush();
sw.Close();
{
tempList.Add(str); //将不重复的权限数据录入到tempList
}
else
{
strNew =strNew+str;
}
else 好像都没落执行过呢!
所以输了,出来的都是空值!
string tmp = null;
Hashtable ht = new Hashtable();
using (System.IO.StreamReader sr = new System.IO.StreamReader(fileName))
{
fileName = System.IO.Path.Combine(Application.StartupPath,"2.txt");
System.IO.StreamWriter sw = new System.IO.StreamWriter(fileName);
while ((tmp = sr.ReadLine()) != null)
{
if (tmp.Trim().Length != 0)
if (ht.Contains(tmp))
sw.WriteLine(tmp);
else
ht[tmp] = 0;
}
sw.Close();
}
static void Main(string[] args)
{
string fileName ="c:/1.txt";
string tmp = null;
Hashtable ht = new Hashtable();
using (System.IO.StreamReader sr = new System.IO.StreamReader(fileName))
{
while ((tmp = sr.ReadLine()) != null)
{
if (tmp.Trim().Length != 0)
if (ht.Contains(tmp))
{ //System.IO.StringWriter sw = new System.IO.StringWriter();
//sw.WriteLine(tmp);
System.Console.WriteLine(tmp); }
else
{
ht[tmp] = 0;
}
}
System.Console.ReadLine();
}
}