c#怎么比较两个txt文本数据,求解

详细问题如下
文件一:1.txt 文件二:2.txt
1.txt中的数据:01,02,03
2.txt中的数据:01 张三,02 李四,03 王五 ,04 王麻子
代码最后显示出来的是 04 王麻子
这代码怎么写????

第1个回答  2013-06-07
简单
string Result=new string();
SteamReader rd1 =new StreamReader(“1.txt”);
string str1=rd.ReadLine();
string[] OneStr=str1.trim().split(',');
SteamReader rd2 =new StreamReader(“2.txt”);
string str2=rd.ReadLine();
string[] TwoStr=str1.trim().split(',');
for (int i=0;i<OneStr.length;i++)
{
for (int j=0;j<TwoStr.length;j++)
{
int isHave=0;
string[] Detail=TwoStr.split(' ');
if (Detail[0]==OneStr[i])
{
isHave=1;
}
if (isHave==0)
{
if (Result.count<=0)
{
Result+=TwoStr[j];
}
else
{
Result+=","+TwoStr[j];
}
}
}
}

最後得到字符串Result本回答被提问者和网友采纳
第2个回答  2013-06-07
不用c#那么复杂吧?
用linux shell命令即可,如果2个文件都不大的话:
grep -v -f 1.txt 2.txt
如果2个文件都很大,效率就会比较低了。
第3个回答  2013-06-07
SteamReader rd =new StreamReader(“1.txt”);
string lin=rd.ReadLine();
string[] cols=lin.Split(',');
new Dictionary<string,string>把每个值都放这里
同样读2,然后对2的每个值再按空格split一次,看前面部分是不是在dictionary里即可